-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEjercicio 5.html
executable file
·47 lines (40 loc) · 1.17 KB
/
Ejercicio 5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ejercicio 5</title>
</head>
<script>
function comprobar_nif(dni){
var numero;
var let;
var letra;
var expresion_regular_dni;
expresion_regular_dni = /^\d{8}[a-zA-Z]$/;
if(expresion_regular_dni.test (dni) == true){
numero = dni.substr(0,dni.length-1);
let = dni.substr(dni.length-1,1);
let=let.toUpperCase();
numero = numero % 23;
letra='TRWAGMYFPDXBNJZSQVHLCKET';
letra=letra.substring(numero,numero+1);
if (letra!=let) {
alert('La letra no corresponde con el DNI.');
}else{
alert('DNI correcto.');
return true;
}
}else{
alert('DNI no válido.');
}
return false;
}</script>
<body>
<p>
<input type="text" id="txtDNI" placeholder='Introduce DNI'> <span class="TESTBUTTON"
onclick="comprobar_nif($('#txtDNI').val())">Probar</span>
</p>
</body>
</html>