Skip to content

Instantly share code, notes, and snippets.

View PecceG2's full-sized avatar
🚀

Giuliano Peccetto PecceG2

🚀
View GitHub Profile
@PecceG2
PecceG2 / Validar Dni
Last active October 28, 2024 13:56 — forked from jvinceso/Validar Dni
Validar Numero de Dni Solo Numeros y longitud 7-8 mediante expresiones regulares en Javascript (Fork: Soporta símbolos y acepta de 7 a 8 caracteres para personas mayores)
function validaDNI(dni){
onlyNumbersDNI = dni.toString().replace(/\D/g, '');
let ex_regular_dni = /^\d{7,8}(?:[-\s]\d{4})?$/;
if(ex_regular_dni.test(onlyNumbersDNI) == true && !(/[a-zA-Z]/g.test(dni)) && onlyNumbersDNI === dni.replace(/(\d)[\s.]+(?=\d)/g, '$1')){
alert('Dni corresponde');
return true;
}else{
alert('Dni erroneo, formato no válido');
return false;
}