5
I’m trying to do a strong javascript password check. Initially I want to check if in the string there is the occurrence of 02 numbers in the following conditions:
- "12vvv": two consecutive numbers or more of anything returning true
- "1a1a": two numbers separated or more returning true
- Must return true in all cases where the text contains 02 numbers or more, regardless of its placement.
I got the expression below that returns true only in case 2 ("1a1a"):
/(\d{1}).(\d{1})/.test("a1a1")
But best option was no 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 that same result with regular expression. Someone knows a regular expression that meets these conditions?
Two numbers followed in the middle or end of the true string as well? example
a22a
oraa22
?– rray
To make it more clear that it takes the following case: the regular expression must identify if the expression has 02 numbers, necessarily, regardless of whether it is sequential or not. The important thing is to identify 02 numbers.
– adrianosymphony