Juan Alvarado wrote in post #1016383: > On Aug 12, 2011, at 9:21 AM, Colin Law wrote: > >> On 12 August 2011 14:08, Niklas Nson <[email protected]> wrote: >>> I need to validate a string from a user (a location for use with >>> geotagging) that is. I want to make sure that the user specify a city >>> and a country in my inp ... So i wrote this => >>> >>> validates :usri_location, >>> :presence => true, >>> :format => {:with => /^[a-zA-Z]+{\,\s}+[a-zA-Z]/i}, > > You have {} instead of () around the , and \s. Also, I don't believe > the ',' has to be escaped (it didn't work with it escaped and it does if > i remove the escaping. With those 2 issues fixed it works for me on > rubular. >
Also \s matches tabs and newlines, so your regex would match things like: xxxx, yyyy and xxxx, yyy so if you just want to match a space, then use a space in your regex: /[a-zA-Z]+, [a-zA-z]+/ -- Posted via http://www.ruby-forum.com/. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

