Foros del Web » Programando para Internet » Javascript »

Problemas al ingresar datos y validas fecha

Estas en el tema de Problemas al ingresar datos y validas fecha en el foro de Javascript en Foros del Web. ... Hola .. buen dia ... Tengo problemilla ... tengo el siguiente js que me valida el formato de una fecha ValidadorFecha.js Código PHP: /********************************************************/ ...
  #1 (permalink)  
Antiguo 09/01/2007, 08:55
Avatar de Superlinux  
Fecha de Ingreso: octubre-2005
Ubicación: Colombia
Mensajes: 662
Antigüedad: 18 años, 6 meses
Puntos: 1
Pregunta Problemas al ingresar datos y validas fecha

... Hola .. buen dia ... Tengo problemilla ... tengo el siguiente js que me valida el formato de una fecha

ValidadorFecha.js
Código PHP:
/********************************************************/
function clsValidator() 
{
    
/* Data members */
    
this.msgError="";                                                            // Return the msg error
    
this.errorColor="#FFC1C1";                                                    // color de error x defecto
    
this.head "ERROR: ... "// encabezado del mensaje de error x defecto
    
this.formatoFecha "ISO"                                                    // formato de fecha x defecto
    
this.error false;            

    
/* Methods */
    ///////////////////////////////////////////////////////////

    
function setEncabezado(head)    
    {
        
this.head head;
    }
    
///////////////////////////////////////////////////////////

    
function AgregarError() {
        
this.error=true;
        
this.msgError += "* "+arguments[0]+"\n";
        for (var 
i=1arguments.length i++) 
        {
            
document.getElementById(arguments[i]).style.backgroundColor=this.errorColor;
        }
    }
    
///////////////////////////////////////////////////////////
    
    
function EliminarError()
    {
        for (var 
i=0arguments.length i++) 
        {
            
document.getElementById(arguments[i]).style.backgroundColor="";
        }
    }
    
///////////////////////////////////////////////////////////
    
    
function setErrorColor(color)
    {
        
this.errorColor color;
    }
    
///////////////////////////////////////////////////////////
    
    
function setFormatoFecha(value)
    {
        
this.formatoFecha value;
    }    
    
    
///////////////////////////////////////////////////////////

    
function Vacio(field,msg
    {
        
this.EliminarError(field);
        if (
document.getElementById(field).value.replace(/ /g'') == "")
        {
            
this.AgregarError(msgfield);
            return 
false
        
}
        return 
true
    
}
    
///////////////////////////////////////////////////////////
    
    
function Fecha(fieldmsg
    {
        
this.EliminarError(field);
    
        var 
datePat;
        var 
formatoCorrecto;
        
        switch(
this.formatoFecha) {
            case 
'ISO':
                
datePat = /^(?:(?:(?:(?:1[6-9]|[2-9]d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(/|-|.)(?:0?21(?:29))$)|(?:(?:1[6-9]|[2-9]d)?d{2})(/|-|.)(?:(?:(?:0?[13578]|1[02])2(?:31))|(?:(?:0?[1,3-9]|1[0-2])2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))2(?:0?[1-9]|1d|2[0-8]))$/;
                
formatoCorrecto "aaaa/mm/dd";
                break;
            case 
'EURO'
                
datePat = /^((([0][1-9]|[12][d])|[3][01])[-/]([0][13578]|[1][02])[-/][1-9]ddd)|((([0][1-9]|[12][d])|[3][0])[-/]([0][13456789]|[1][012])[-/][1-9]ddd)|(([0][1-9]|[12][d])[-/][0][2][-/][1-9]d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-/][0][2][-/][1-9]ddd)$/;
                
formatoCorrecto "dd/mm/aaaa";
                break;
            case 
'ANSI':
                
datePat = /^((d{2}(([02468][048])|([13579][26]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|([1-2][0-9])))))|(d{2}(([02468][1235679])|([13579][01345789]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(s(((0?[1-9])|(1[0-2])):([0-5][0-9])((s)|(:([0-5][0-9])s))([AM|PM|am|pm]{2,2})))?$/;
                
formatoCorrecto "aaaa/mm/dd hh:mm:ss am/pm";
                break;
        }        
        
        var 
matchArray document.getElementById(field).value.match(datePat);
        if (
matchArray != null) return true
        
else
        {
            
msg += ' [formato: '+formatoCorrecto+']'
            
this.AgregarError(msgfield);
            return 
false;        
        }
    }
    
///////////////////////////////////////////////////////////
    
    
function Longitud(fieldoperatorlengthmsg)
    {
        
this.EliminarError(field);
        if (
operator == "="operator "==";
        if ( !(eval(
"document.getElementById(field).value.length "+operator+" length")) )
        {
            
this.AgregarError(msgfield);
            return 
false
        
}
        return 
true
    
}
    
///////////////////////////////////////////////////////////
    
    
function Valor(fieldoperatorvalormsg)
    {
        
this.EliminarError(field);
        if (
operator == "="operator "==";
        if ( !(eval(
"document.getElementById(field).value "+operator+" valor")) )
        {
            
this.AgregarError(msgfield);
            return 
false
        
}
        return 
true
    
}
    
///////////////////////////////////////////////////////////

    
function Validar() 
    {
        return !
this.error;
    }
    
///////////////////////////////////////////////////////////

    
function getErrors() 
    {
        
alert(this.head+"\n\n"+this.msgError);
    }
    
///////////////////////////////////////////////////////////

    
this.setEncabezado setEncabezado;
    
this.setErrorColor setErrorColor;
    
this.setFormatoFecha setFormatoFecha;
    
this.getErrors getErrors;
    
this.AgregarError AgregarError;
    
this.EliminarError EliminarError;
    
this.Vacio Vacio;
    
this.Fecha Fecha;
    
this.Validar Validar;    
}
////////////////////////////////////////////////////////////////// 
Con el cual valido un input a ingresar ... pero como para ingresar el dato uso un boton submit .... aunque la fecha sea ingresada erroneamente el dato se me incorpora en la BD.

index.php
Código PHP:
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function validate() 
{
    var Validar = new clsValidator();
    //**********************************************************
    //Uso todos los valores por defecto
    //**********************************************************
    //Se podrian cambiar:
    //Validar.setEncabezado("[- Hay errores en el formulario -]");
    //Validar.setErrorColor("#FFCC00");
    //validar.setFormatoHora('24');
    //validar.setFormatoFecha('ISO');
    
    //5- Valido que la fecha sea correcta
    Validar.Fecha("fechafact", "Fecha de facturacion no válida");
    Validar.Fecha("fechadesp", "Fecha de despacho no válida");
    
    //Disparo la Validación
    if (Validar.Validar()) 
        alert("Formato de fecha es correcto ... presione enter para continuar");
    else Validar.getErrors(); 
}//Fin function validate() 
//-->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript" srcValidadorFecha.js">

<form name = forma action = "" method = post id="forma" onSubmit="return jsValidateForm(this)"> 
<input type="hidden" name="mode" value="submit">
<?php 

<input name="fechafact" type="text" id="fechafact" value="<?=$fechafact?>" size="10" maxlength="10" style="background:#ffffff" onFocus="encender(this)" onBlur="apagar(this)" onKeyPress="return tabular(event,this)">
                          </
font></font></font></font></font></font></font> </td>

<
input name="fechadesp" type="text" id="fechadesp" value="<?=$fechadesp?>" size="10" maxlength="10" style="background:#ffffff" onFocus="encender(this)" onBlur="apagar(this)" onKeyPress="return tabular(event,this)">

<
input name="siguiente" id="siguiente" type="submit" class="botones" onClick="validate()" value="Siguiente">

</
body>
</
html>
Gracias por la ayuda ----
__________________
"La vida sigue su curso, tú toma parte de ella."
  #2 (permalink)  
Antiguo 10/01/2007, 13:39
Avatar de Superlinux  
Fecha de Ingreso: octubre-2005
Ubicación: Colombia
Mensajes: 662
Antigüedad: 18 años, 6 meses
Puntos: 1
Re: Problemas al ingresar datos y validas fecha

... encontre la solucion ... solo usando un calendario grafico ... bye ... y gracias.
__________________
"La vida sigue su curso, tú toma parte de ella."
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:08.