开发者

Regular expression for Alphabet, numeric and special character

Can 开发者_C百科someone please give regular expression for a word, which should have:

  1. length in the range of 6 to 10
  2. It must be a combination of alphanumeric, numeric and special character (non-alphanumeric character)


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


You should do this as a sequential series of tests:

  1. Is it of the right length? ^.{6,10}$
  2. Does it contain an alphabetic character? [A-Za-z]
  3. Does it contain a digit? [0-9]
  4. Does it contain a "special character" [^0-9A-Za-z]

If it passes all four tests, it's ok.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜