I need to check that a value(key) has:
- Minimum 8 characters.
- Upper case and lower case.
- Numbers.
- It can contain
!
or?
, but no other special characters.
So far I have the following:
function enRango(x, min, max) {
return ((x - min) * (x - max) <= 0);
}
const clave = document.getElementById('clave');
function comprobarContraseña(clave) {
let resul = 0;
for (let i = 0; i < clave.length; i++) {
if (!enRango(clave.charCodeAt(i), 34, 47) || !enRango(clave.charCodeAt(i), 58, 62)) {
if (minusculas.test(clave)) {
if (numeros.test(clave)) {
resul = 1;
console.log('has entrado hasta el final');
return resul;
}
}
} else {
resul = 1;
return resul;
}
if (minusculas.test(clave) && numeros.test(clave)) {
console.log('estas en el minusculas y numeros');
return resul;
}
}
}
minusculas
and numeros
they are two regular expressions that I have created, but since I do not have much knowledge in the matter, I think that I have some mistake when checking.
const minusculas = new RegExp('^[a-z]+$');
const numeros = new RegExp('^[0-9]+$');
I think everything can be checked directly with a Regular Expression but I don't know exactly how to do it.