ruby - Regex to validate strings having only characters (without special characters but with accented characters), blank spaces and numbers -


i using ruby on rails 3.0.9 , validate string can contain characters (case insensitive characters), blank spaces , numbers.

more:

  • special characters are not allowed (eg: !"£$%&/()=?^) except - , _;
  • accented characters are allowed (eg: à, è, é, ò, ...);

the regex know this question ^[a-za-z\d\s]*$ not validate special characters , accented characters.

so, how should improve regex?

i wrote ^(?:[^\w_]|\s)*$ answer in question referred to (which have been different if i'd known wanted allow _ , -). not being ruby guy myself, didn't realize ruby defaults not using unicode regex matching.

sorry lack of ruby experience. what want use u flag. switches unicode (utf-8), accented characters caught. here's pattern want:

^[\w\s-]*$ 

and here in action @ rubular. should trick, think.

the u flag works on original answer well, though 1 isn't meant allow _ or - characters.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -