Reputation: 301
Can someone please give regular expression for a word, which should have:
Upvotes: 0
Views: 6111
Reputation: 336128
So in other words, all characters are allowed, but at least one letter, one digit, and one "something else" character is required?
^(?=.*\p{L})(?=.*\p{N})(?=.*[^\p{L}\p{N}]).{6,10}$
I wouldn't impose a maximum length restriction on a password, though...
Explanation:
^ # Match start of string
(?=.*\p{L}) # Assert that string contains at least one letter
(?=.*\p{N}) # Assert that string contains at least one digit
(?=.*[^\p{L}\p{N}]) # Assert that string contains at least one other character
.{6,10} # Match a string of length 6-10
$ # Match end of string
Upvotes: 5
Reputation: 15603
You should do this as a sequential series of tests:
^.{6,10}$
[A-Za-z]
[0-9]
[^0-9A-Za-z]
If it passes all four tests, it's ok.
Upvotes: 0