N
Nacho
Hello..
I have one problem with my reusable function to validate date..
I want to use this function to all my web project no validate date, but
It's works fine if I have one textbox to validate in the same form, If
I have two textbox the return doesn't works correctly.. how can I do
this?
if (document.Form1.TxtFechaIng.value!=''){
return validafch(document.Form1.TxtFechaIng.value);
}
if (document.Form1.txtFchNaci.value!=''){
return validafch(document.Form1.txtFchNaci.value);
}
thanks
nacho
this is my function:
function anyoBisiesto(anyo)
{
var anyo;
if (anyo < 100)
var fin = anyo + 1900;
else
var fin = anyo ;
if (fin % 4 != 0)
return false;
else
{
if (fin % 100 == 0)
{
if (fin % 400 == 0)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
}
function validafch(fecha){
var a, mes, dia, anyo, febrero,regresa;
a=fecha;
dia=a.split('/')[0];
mes=a.split('/')[1];
anyo=a.split('/')[2];
if ((isNaN(dia)==true) || (isNaN(mes)==true) ||
(isNaN(anyo)==true))
{
alert('La fecha introducida debe estar formada solo por numeros');
regresa=1;
}
if (anyoBisiesto(anyo))
febrero=29;
else
febrero=28;
if ((mes<1) || (mes>12))
{
alert('El mes introducido no es valido. Por favor, introduzca un
mes correcto');
regresa=1;
}
if ((mes==2) && ((dia<1) || (dia>febrero)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) ||
(mes==10) || (mes==12)) && ((dia<1) || (dia>31)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) ||
(dia>30)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if ((anyo<1900) || (anyo>2010))
{
alert('El año introducido no es valido.');
regresa=1;
}
if (regresa==1)
{return false} <---this is the problem
else{return true}
}
I have one problem with my reusable function to validate date..
I want to use this function to all my web project no validate date, but
It's works fine if I have one textbox to validate in the same form, If
I have two textbox the return doesn't works correctly.. how can I do
this?
if (document.Form1.TxtFechaIng.value!=''){
return validafch(document.Form1.TxtFechaIng.value);
}
if (document.Form1.txtFchNaci.value!=''){
return validafch(document.Form1.txtFchNaci.value);
}
thanks
nacho
this is my function:
function anyoBisiesto(anyo)
{
var anyo;
if (anyo < 100)
var fin = anyo + 1900;
else
var fin = anyo ;
if (fin % 4 != 0)
return false;
else
{
if (fin % 100 == 0)
{
if (fin % 400 == 0)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
}
function validafch(fecha){
var a, mes, dia, anyo, febrero,regresa;
a=fecha;
dia=a.split('/')[0];
mes=a.split('/')[1];
anyo=a.split('/')[2];
if ((isNaN(dia)==true) || (isNaN(mes)==true) ||
(isNaN(anyo)==true))
{
alert('La fecha introducida debe estar formada solo por numeros');
regresa=1;
}
if (anyoBisiesto(anyo))
febrero=29;
else
febrero=28;
if ((mes<1) || (mes>12))
{
alert('El mes introducido no es valido. Por favor, introduzca un
mes correcto');
regresa=1;
}
if ((mes==2) && ((dia<1) || (dia>febrero)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) ||
(mes==10) || (mes==12)) && ((dia<1) || (dia>31)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) ||
(dia>30)))
{
alert('El dia introducido no es valido. Por favor, introduzca un
dia correcto');
regresa=1;
}
if ((anyo<1900) || (anyo>2010))
{
alert('El año introducido no es valido.');
regresa=1;
}
if (regresa==1)
{return false} <---this is the problem
else{return true}
}