I’m finding a regular expression which adheres below rules.
Allowed Characters
Alphabet : a-z / A-Z
Numbers : 0-9
Special Characters : ~ @ # $ ^ & * ( ) – _ + = [ ] { } | \ , . ? :
(spaces should be allowed)
Not Allowed
Special Characters : < > ‘ ” / ; ` %
For the allowed characters you can use
to validate a complete string that should consist of only allowed characters. Note that
-is at the end (because otherwise it’d be a range) and a few characters are escaped.For the invalid characters you can use
to check for them.
To combine both into a single regex you can use
but you’d need a regex engine that allows lookahead.