Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/05/2011, 05:01
luisoroz
 
Fecha de Ingreso: febrero-2011
Mensajes: 4
Antigüedad: 13 años, 3 meses
Puntos: 0
No me hace la valicacion del NIE en este código

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Validación</title>

<script>
function ValidaCampos(formulario) {
var expresion_regular_dni = /^\d{8}[a-zA-Z]$/; // 8 cifras numéricas más un carácter alfabético.
var expresion_regular_nie = /[x|X|y|Y]\d\d\d\d\d\d\d[a-zA-Z]/;

if(expresion_regular_dni.test(formulario.dni.value )==false) {
alert('El campo del DNI no es válido, DNI= 9 números/letra sin espacios');
return false; // sale de la función y NO envía el formulario
}
if(expresion_regular_nie.test(formulario.nie.value )==false) {
alert('El campo del NIE no es válido, NIE= letra/7 números/letra sin espacios');
return false; // sale de la función y NO envía el formulario
}
alert('Gracias por rellenar nuestro formulario correctamente.');
return true; // sale de la función y SÍ envía el formulario
}
</script>

<script type="text/javascript">

function nie(nie) {
niereg = /[x|X|y|Y]\d\d\d\d\d\d\d[a-zA-Z]/;
if (nie.length != 9 || !niereg.test(nie))
alert("NIE erroneo, vuelva a intentarlo");
else
alert('NIE CORRECTO !!, continue con el formulario');
}

function nif(dni) {
numero = dni.substr(0,dni.length-1);
let = dni.substr(dni.length-1,1);
numero = numero % 23;
letra='TRWAGMYFPDXBNJZSQVHLCKET';
letra=letra.substring(numero,numero+1);
if (letra!=let)
alert('DNI erroneo, vuelva a intentarlo');
else
alert('DNI CORRECTO !!, continue con el formulario');
}
</script>

</head>

<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top">

<td><table border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">

<td><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" class="cont"><form action="fin_solicitud_sicliente.php" onSubmit="return ValidaCampos(this)" method="post" name="formulario">
<table width="110%" border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
<td align="left" valign="top"><p>
<input name="dni" type="text" id="dni" size="9" maxlength="9">
<span class="texpeq">ej. <strong>37742822M</strong></span> <span class="texpeq">(sin espacios ni guiones)
<input type="button" onClick="nif(formulario.dni.value);" value="Validar DNI"/>

</span></p>
<p>
<input name="nie" type="text" id="nie" size="9" maxlength="9">
<span class="texpeq">ej. <strong>X7742822M</strong></span> <span class="texpeq">(sin espacios ni guiones)
<input type="button" onClick="nie(formulario.nie.value);" value="Validar NIE"/>
</span></p></td>
</tr>
<tr>
<td align="center" valign="top" class="form_txt2"><input type="submit" name="Submit" value="Enviar Solicitud"></td>
</tr>
</table>
</form></td>
</tr>

</table></td>
</tr>
</table>
</body>
</html>

Última edición por luisoroz; 19/05/2011 a las 05:13