I'm trying to do a strong password check in javascript. Initially I want to check if there are 02 numbers in the string under the following conditions:
I got the expression below that returns true only in case 2 ("1a1a"):
/(\d{1}).(\d{1})/.test("a1a1")
But better option was without regular expression:
function hasTwoNumber(text) {
var arr = text.split(""),
tamanho = arr.length,
qtd = 0;
for (var i = 0; i < tamanho; i++) {
if (/[0-9]/.test(arr[i])) {
qtd++;
}
}
return qtd > 1;
}
console.log(hasTwoNumber("1a1a")); //true
console.log(hasTwoNumber("11aa")); //true
I would like to get this same result with regular expression. Does anyone know a regular expression that meets these conditions?