-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentoidjs.html
More file actions
42 lines (34 loc) · 1.37 KB
/
documentoidjs.html
File metadata and controls
42 lines (34 loc) · 1.37 KB
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
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/localization/messages_es.js"></script>
</head>
<form method="post" id="selector" action="leerFicha.php" novalidate>
<label for="cnif">NIF (opcional)</label>
<input id="cnif" name="nif"><br>
<input type="submit">
<input type="reset">
</form>
<script>
function esNIF(value, element) {
var referencia = 'TRWAGMYFPDXBNJZSQVHLCKE';
var letra = value.substring(value.length - 1);
var numero = parseInt(value.substring(0, value.length - 1));
if (referencia.charAt(numero % 23) === letra) {
return true;
} else {
return false;
}
}
jQuery.validator.addMethod("esnif", esNIF, "No es un NIF válido");
$("#selector").validate({
submitHandler: function (form) {
form.submit();
},
rules: {
nif: {
esnif: true
}
}
});
</script>