I need to validate a password that matches the following criteria:
- minimum 8 characters
- contain a combination of numbers and letters
- must not enforce special characters
The follow regular expression is what I came up with:
^{8,}.(?=*\d)(?=.*[a-zA-Z])&
but this is failing on:
- !password1
- password1
- Password1
From what I can gather, trying to investigate RegEx, {8,}
means minimum of 8 and don't care about the maximum, \d
specifies digits, whitespaces and special characters. The a-z make开发者_C百科s sense.
Try:
^(?=.*\d)(?=.*[a-zA-Z]).{8,}$
See it @work
simple not most efficient way:
^[a-zA-Z0-9!.-_]{8,}$
Replace !.-_
with the list of special characters you'd like to allow
精彩评论