I am using Ruby on Rails 3.0.9 and I would like to validate a string that can contain only characters (case insensitive characters), blank spaces and numbers.
I wrote the
^(?:[^\W_]|\s)*$ answer in the question you referred to (which actually would have been different if I'd known you wanted to allow _ and -). Not being a Ruby guy myself, I didn't realize that Ruby defaults to not using Unicode for regex matching.
Sorry for my lack of Ruby experience. What you want to do is use the
u flag. That switches to Unicode (UTF-8), so accented characters are caught. Here's the pattern you want:
And here it is in action at Rubular. This should do the trick, I think.
u flag works on my original answer as well, though that one isn't meant to allow _ or - characters.