Hi all, I have the following line in my model: validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z]{2}/, :on => :create However this still does allow me to create a postal code such as: 5444 ABC which is incorrect, because it should only be allowed if two characters are supplied at the end. In java the same regex is working, what am I doing wrong here? Regards, Harm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 20 October 2006 15:17, Harm de Laat wrote:> Hi all, > > I have the following line in my model: > > validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z]{2}/, :on => > > :create > > However this still does allow me to create a postal code such as: > > 5444 ABC > > which is incorrect, because it should only be allowed if two characters are > supplied at the end. > > In java the same regex is working, what am I doing wrong here?Add ^ at the beginning and $ - at the end: validates_format_of :postal_code, :with => /^\d{4}\s*[a-zA-Z]{2}$/, :on => :create --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 20, 2006, at 4:17 AM, Harm de Laat wrote:> I have the following line in my model: > > validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z] > {2}/, :on => :create > > However this still does allow me to create a postal code such as: > > 5444 ABCYour expression looks fine, but you can''t expect all parsers to behave identically. You might try doing [a-zA-Z][a-zA-Z]. Jose ....................................................... Jose Hales-Garcia UCLA Department of Statistics jose-oNoWckAxTcaFhjwBz98joA@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks Maxim, That seemed to be it! Regards, Harm! On 10/20/06, Maxim Kulkin <maxim.kulkin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 20 October 2006 15:17, Harm de Laat wrote: > > Hi all, > > > > I have the following line in my model: > > > > validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z]{2}/, :on => > > > > :create > > > > However this still does allow me to create a postal code such as: > > > > 5444 ABC > > > > which is incorrect, because it should only be allowed if two characters > are > > supplied at the end. > > > > In java the same regex is working, what am I doing wrong here? > Add ^ at the beginning and $ - at the end: > > validates_format_of :postal_code, :with => /^\d{4}\s*[a-zA-Z]{2}$/, :on > => :create > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---