Reputation: 2857
I am trying to validate a text box using regular expression. I want to add alphabets, numbers and some special characters like "& - / . # , space".
I have tried with this
/^[a-zA-Z0-9&-/.#,\s]*$/
.
It is working fine except the *. I want to prevent * symbol.
Upvotes: 2
Views: 134
Reputation: 55
Put & at the end of regex Like below
/^[a-zA-Z0-9-/.#,\s&]*$/
Upvotes: 1
Reputation: 138007
You should escape the hyphen and slash:
/^[a-zA-Z0-9&\-\/.#,\s]*$/
&-/
is interpreted as a range, just like a-z
, which include *
and some other characters.
Escaping the slash is not mandatory here, but I always try to escape it in regex literals (/this syntax/
).
Upvotes: 1