简体   繁体   中英

Password must contain any one of the following criteria

Password must contain any one of the following criteria

1)One Uppercase 2)one lower case 3)one Number 4)one special character.

in the above criteria if any three-match then it's allowed to a valid password.

like below format.

1) One number, one lower case alphabet, one uppercase alphabet ---> valid password

or

2)one number, one lower case alphabet, and one special character ---> valid password

or

3)one number, one uppercase alphabet, and one special character ---> valid password.

Please help me how to write the regular expression for the above criteria.

my requirement is any three combinations one number, one alphabet, one special character. it's like permutation combination format. if I write /(?=. \\d)(?=. [az])(?=. [AZ])(?=. [-._@^]).{8,16}/ format I need to verify so many conditions .so any another way.

Thanks in advance.

Assuming your special characters are [\\^$.|?*+()

1) One number, one lower case alphabet, one uppercase alphabet ---> valid password

[0-9][a-z][A-Z]

or

2) one number, one lower case alphabet, and one special character ---> valid password

[0-9][a-z][\[\\\^\$\.\|\?\*\+\(\)]

or

3) one number, one uppercase alphabet, and one special character ---> valid password.

[0-9][A-Z][\[\\\^\$\.\|\?\*\+\(\)]

Combine them with OR (|)

[0-9][a-z][A-Z]|[0-9][a-z][\[\\\^\$\.\|\?\*\+\(\)]|[0-9][A-Z][\[\\\^\$\.\|\?\*\+\(\)]

If the order of the pswd chars is not important so:

  1. One number, one lower case alphabet, one uppercase alphabet ---> valid password: \\d[az][AZ]
  2. One number, one lower case alphabet, and one special character ---> valid password: \\d[az][\\[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)]
  3. One number, one uppercase alphabet, and one special character ---> valid password: \\d[AZ][\\[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)]

So if it's combined in one regex: (\\d[az][AZ])|(\\d[az][\\[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)])|(\\d[AZ][\\[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)])

Check it up here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM