Password Regex

I want to confirm the password. Below are my requirements.

Minimum Password Length: 8
Minimum Lower Case Character: 1
Minimum upper case characters: 1
Minimum number of numeric characters: 1

How to write a regex for this?

+4
source share
3 answers

You can use the following regular expression:

^(?=.*[az])(?=.*[AZ])(?=.*[0-9]).{8,}$ 
+4
source

I agree with @Russell, the function is the best choice for password verification. And it's hard to imagine that one Regex handles all of these cases. I think you will have to check each in turn.

In an individual expression of a Regex expression:

  • .{8} matches at least 8 characters
  • [az] matches one lowercase character
  • [az] matches one uppercase character
  • [0-9] matches the digit

As stated, they would only be useful for client-side validation before the server performs an in-depth validation.

+2
source

Below you will find the regex for your requirements:

 (?=^.{8}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[AZ])(?=.*[az]).*$ 
0
source

Source: https://habr.com/ru/post/1342587/


All Articles