Reputation: 7565
I have Drupal 7
site. I am using contributed "Field Validation" module for validation.
I need to validate textbox. This textbox should allow only characters, numerics & space.
I tried with the following regex but not allowing spaces.
[a-zA-Z0-9]
^[a-zA-Z0-9_ ]*$
/^[a-z\d\-_\s]+$/i
Please note here I am talking about regex in FieldValidation module of drupal.
Upvotes: 1
Views: 890
Reputation: 81
This should work ^[\w\s]+$
^ - assert position at start of the string
\w - Matches alphanumeric (same as [a-zA-Z0-9_])
\d - Matches digits (same as [0-9])
+ - Match the previous element one or more times (as many as possible)
$ - assert position at end of the string
This is what is allowed to write in this text box
ABCdef 123_
P.S. if this ^[\w\s]+$
isn't work try /^[\w\s]+$/
Upvotes: 1