I'm building a form in ASP.Net using VB and I have a text box that I'd like to validate against the following rules:
!@#$%^&*+-=(){}:;,'./?Those requirements aren't set by me...That's just what I have to work with.
So, the following would match:
TestUserPass
Te$tU$e^p@%}
testuserpass
test{user}n@ame
The following would not match:
8392039
dhj#5|3j
Hopefully that gives an idea of what I'm looking for...
Here's what I have so far: \b[a-zA-Z0-9!@#\$%\^&\*\+=\(\){}:;,'\./\?-]{6,20}\b
I believe that's working for everything EXCEPT the invalidating the instance where the entry is all numbers. It's the all numbers portion that I've been struggling with, though perhaps someone will find a flaw in what I already have. Any help is greatly appreciated!
You should use different anchors, and you can use a negative lookahead assertion to make sure that other characters than digits are present:
^(?![0-9]*$)[a-zA-Z0-9!@#\$%^&*+=(){}:;,'./?-]{6,20}$
Also, you don't need to escape (most) regex metacharacters within a character class as they don't have a special meaning there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With