I need a regex expression for pattern validation that should allow only alphanumeric words and some special characters that are !@#$%^&*()-_
I tried that expression but it didn't work
Validators.pattern("^[a-zA-Z0-9!@#$%^*-_&()\\\"]*$")
I need a regex expression for pattern validation that should allow only alphanumeric words and some special characters that are !@#$%^&*()-_
I tried that expression but it didn't work
Validators.pattern("^[a-zA-Z0-9!@#$%^*-_&()\\\"]*$")
Your problem is the *-_
inside your character set. This is treated as a range of all the characters from *
to _
i.e. *
, +
, ,
... ]
, ^
, _
(I've left out the rest of the characters for brevity). You need to either put the -
at the beginning or end of the set, or escape it within the set e.g.
Validators.pattern("^[a-zA-Z0-9!@#$%^*_&()\\\"-]*$")