Validar fecha nacimiento php

Tengo 3 archivos (index.php & proceso.php & funciones.js)
(index.php)
<td width="50%" align="right" nowrap="nowrap">Fecha Nacimiento</td>
<td nowrap="nowrap">
<select name="dia" id="dia">
<option value="-1">Día </option>
<?php
for($i=1;$i<=31;$i++){
if(strlen($i)==1){ $i = "0".$i; }
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
-
<select name="mes" id="mes">
<option value="-1">Mes</option>
<?php
for($i=1;$i<=12;$i++){
if(strlen($i)==1){ $i = "0".$i; }
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
-
<select name="ano" id="ano">
<option value="-1">Año</option>
<?php
for($i=1900;$i<=date("Y");$i++){
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</tr>
<tr>
(funcion.js)
function valida_fecha(fec){
var sw=1, dia, mes, ano;
if (fec.length == 0)
return true
x_arr=fec.split("/");
if (x_arr.length==3){
// Valida que sean números enteros
if (isNaN(parseInt(x_arr[0]))) sw=0;
if (isNaN(parseInt(x_arr[1]))) sw=0;
if (isNaN(parseInt(x_arr[2]))) sw=0;
if (sw==1){
dia=x_arr[0];mes=x_arr[1];ano=x_arr[2];
if( (mes<1) || (mes>12) ) sw=0;
if( (dia<1) || (dia>31) ) sw=0;
if (ano<999) sw=0;
if (sw==1){
if (mes==2){// Si es bisiesto
if ((ano%4!=0) && (dia>28)) sw=0;
else if (dia>29) sw=0;
}
if ( ((mes==4) || (mes==6) || (mes==9) || (mes==11) ) && (dia>30) ) sw=0;
}
}
}
else {sw=0}
if (sw==0)
return false;
else
return true
}
function validar(){
if(document.getElementById("dia").value.length == -1){
texto = texto + " - dia\n";
error++;
}
if(document.getElementById("mes").value.length == -1){
texto = texto + " - m\nes";
error++;
}
if(document.getElementById("ano").value.length == -1){
texto = texto + " - año\n";
error++;
} }

Añade tu respuesta

Haz clic para o