ruby - Regular Expression of only spaces, letters, and numbers no special characters -


i trying make regular expression validates letters, numbers , spaces only. dont want special characters accepted (i.e. # )(*&^%$@!,)

i have been trying several things nothing has given me letters(uppercase & lowercase), numbers, , spaces.

so should accept this...

john stevens 12  james stevens  willcall12 

or

12cell space 

but not this

12cell space!  john@stevens  james 12 fall# 

i have tried following

^[a-za-z0-9]+$  [\w _]+  ^[\w_ ]+$ 

but allow special characters or dont allow spaces. ruby validation.

you got right. use this:

/\a[a-z0-9\s]+\z/i

\s matches whitespace characters including tab. use (space) within square brackets if need exact match space.

/i @ end means match not case sensitive.

take @ rubular testing regexes.

edit: pointed out jesus castello, scenarios 1 should use \a , \z instead of ^ , $ denote string boundaries. see difference between \a \z , ^ $ in ruby regular expressions explanation.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -