JavaScript for password verification

Can someone help me write a regex in the following description?

The password contains characters from at least three of the following five categories:

  • English uppercase characters (A - Z)
  • English lowercase letters (a - z)
  • Base 10 digits (0 - 9)
  • Non-alphanumeric (e.g.:!, $, #, Or%)
  • Unicode characters

The minimum password length is 6.

+3
source share
2 answers

- . , . , , , .

if (password.length < 6) {
  alert("password needs to be atleast 6 characters long"); 
}

var count = 0;
//UpperCase
if( /[A-Z]/.test(password) ) {
    count += 1;
}
//Lowercase
if( /[a-z]/.test(password) ) {
    count += 1;
}
//Numbers  
if( /\d/.test(password) ) {
    count += 1;
} 
//Non alphas( special chars)
if( /\W/.test(password) ) {
    count += 1;
}
if (count < 3) {
  alert("password does not match atleast 3 criterias"); 
}

, , . .

+3

[A-Za-z!$#%\d\u0100]{6} aS1%eĀ.

\u0100 À. , . .

EDIT: 6 [A-Za-z!$#%\d\u0100]{6,}.

EDIT 2: Unicode ( Latin Extended-B), ^[A-Za-z!$#%\d\u0100-\u017f]{6,}$. Unicode .

3: , , . .

function isValidPassword(password) {    
    var unicodeRange = "\\u0100-\\u0105";
    var criteria = ["A-Z","a-z","\\d","!$#%",unicodeRange];

    // check whether it doesn't include other characters
    var re = new RegExp("^[" + criteria.join("") +"]{6,}$");
    if(!re.test(password)) return false;

    var minSatisfiedCondition = 3;
    var satisfiedCount = 0;
    for( var i=0; i < criteria.length; i++) {
      re = new RegExp("[" + criteria[i] + "]");
      if(re.test(password)) ++satisfiedCount;

    }
    return (satisfiedCount >= minSatisfiedCondition);
}​

.

+1

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


All Articles