Kgn-web
Kgn-web

Reputation: 7565

Regex for allowing alphanumeric and space in Field Validation Module of Drupal

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.

Please note here I am talking about regex in FieldValidation module of drupal.

Upvotes: 1

Views: 890

Answers (1)

RandomNoobName
RandomNoobName

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

Related Questions