5
I have the following problem, I need to validate a password field with at least 8 characters, being at least 2 numbers and the rest letters, they can be in any position.
12abcdef abcdef12
The expression I made works in the above cases:
function vSenha(senha) {
return /^(((?=.*[a-z])(?=.*\d{2,}).{8,16})|(?=.*\d{2,})(?=.*[a-z]).{8,16})$/.test(senha);
}
But if I put a letter and number interspersed, the expression doesn’t work. I was trying to assemble an operator OR with regex but not successful.
Ex of how it doesn’t work:
1a2b3c4d
Can there be other characters than letters? with the
!?#€%&
?– Sergio
@Sergio, no no, it’s just letters, I forgot to ask the question
– haykou