开发者

Regex for password verification

I want to validate password .The following are my requirements.

Minimum password length: 8

Minimum number of lower case characters: 1

Minimum number of upper case characters: 1

Minimu开发者_如何学编程m number of numeric characters: 1

How to write a regex for this ?


You can use the following regex:

^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,}$


I agree with @Russell, a function is a better choice for password validation. And it's hard to imagine a single Regex handling all these cases. I think you would have to check each one in turn.

Individually, the Regex expressions are:

  • .{8} matches at least 8 characters
  • [a-z] matches a single lowercase character
  • [A-Z] matches a single uppercase character
  • [0-9] matches a digit

That having been said, these would only be useful for client-side checking prior to having the server do in-depth validation.


Please find below regex for your requirements:

(?=^.{8}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$ 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜