views:

14

answers:

1
validates_format_of :first_name, :with => /\A\w+\Z/

The validation doesn't pass if there are non-english character in first name, like Mölläinen. Changing Rails locale doesn't help. So how do you do culture/locale sensitive validation then?

If the locale is EN, then \w should map to [a-zA-Z0-9_], but if it's FI, then it should map to [a-zA-Z0-9_äöåÄÖÅ] and so on.

+1  A: 

Try /\A[[:alpha:]]+\Z/. This should be locale aware, at least in Ruby 1.9.

But you might want to allow other characters too. Anna-Lena is a common name in Germany, for example.

Tim Pietzcker