Add national ID document validation
This commit is contained in:
parent
68b528b960
commit
322a464eb7
|
@ -7,6 +7,7 @@
|
|||
<link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" />
|
||||
<script src="../../static/jquery-3.5.1.min.js"></script>
|
||||
<script src="../ajax.js"></script>
|
||||
<script src="../validate_id.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
|
@ -15,7 +16,7 @@
|
|||
$pdo = connectDatabase();
|
||||
$regions = fetchRegions($pdo);
|
||||
?>
|
||||
<form method="post" action="../patient_management.php">
|
||||
<form name="create_form" method="post" action="../patient_management.php" onsubmit="return validateDNI();">
|
||||
<div class="input-group">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="nombre" value="">
|
||||
|
@ -62,7 +63,7 @@
|
|||
<input type="text" name="pais" value="">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<button class="btn" type="submit" name="create" >Guardar</button>
|
||||
<button class="btn" type="submit" name="create">Guardar</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php closeDatabase($pdo); ?>
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
function validateDNI(dni) {
|
||||
var number, let, letra;
|
||||
var expresion_regular_dni = /^[XYZ]?\d{5,8}[A-Z]$/;
|
||||
function checkDNI(dni) {
|
||||
var number, let, letter;
|
||||
var regex = /^[XYZ]?\d{5,8}[A-Z]$/;
|
||||
|
||||
dni = dni.toUpperCase();
|
||||
|
||||
if(expresion_regular_dni.test(dni) === true){
|
||||
if(regex.test(dni) === true){
|
||||
number = dni.substr(0,dni.length-1);
|
||||
number = number.replace('X', 0);
|
||||
number = number.replace('Y', 1);
|
||||
number = number.replace('Z', 2);
|
||||
let = dni.substr(dni.length-1, 1);
|
||||
number = number % 23;
|
||||
letra = 'TRWAGMYFPDXBNJZSQVHLCKET';
|
||||
letra = letra.substring(number, number+1);
|
||||
if (letra != let) {
|
||||
letter = 'TRWAGMYFPDXBNJZSQVHLCKET';
|
||||
letter = letter.substring(number, number+1);
|
||||
if (letter != let) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
|
@ -21,3 +21,13 @@ function validateDNI(dni) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function validateDNI(){
|
||||
var dni = document.forms["create_form"]["documento_identificativo"];
|
||||
if(!checkDNI(dni.value)){
|
||||
alert("El DNI/NIE no es correcto");
|
||||
return false;
|
||||
}
|
||||
alert("El DNI/NIE es correcto");
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue