Created
May 28, 2012 11:24
-
-
Save BenjaminGuV/2818641 to your computer and use it in GitHub Desktop.
validar datos con jquery prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Validar(){ | |
//this.id = id; | |
} | |
Validar.prototype.vacio = function( id ) { | |
this.id = id; | |
if ( this.id == "" ) { | |
this.id = false; | |
} | |
return this.id; | |
} | |
Validar.prototype.fecha = function( datos, patron ){ | |
this.datos = datos; | |
this.patron = patron; | |
// /^\d{2}\/\[a-zA-Z]{3}\/\d{4}$/ | |
if ( !this.datos.match( this.patron ) ) { | |
this.datos = false; | |
} | |
return this.datos; | |
} | |
Validar.prototype.fechaActual = function ( hoyes, diff ) { | |
this.hoyes = hoyes; | |
var tmpTiempo = this.hoyes.split( ' ' ); | |
var tmpFecha = tmpTiempo[0].split('-'); | |
var tmpTime = tmpTiempo[1].split(':'); | |
var dia = tmpFecha[2]; | |
var mes = tmpFecha[1]; | |
var anio = tmpFecha[0]; | |
var min = tmpTime[1]; | |
var hora = parseInt( tmpTime[0], 10 ); | |
var fechaD = new Date( anio, mes, dia, hora + diff, min ); | |
return fechaD; | |
} | |
Validar.prototype.cambIniFin = function( fechaCamb, patron, hora, min ){ | |
this.fechaCamb = fechaCamb; | |
this.patron = patron; | |
this.hora = hora; | |
this.min = min; | |
var valor = this.fechaCamb.split( this.patron ); | |
var dia = valor[0]; | |
var mes = this.mesInteger( valor[1] ); | |
var anio = valor[2]; | |
var fechaIF = new Date( anio, mes - 1, dia, this.hora, this.min ); | |
return fechaIF; | |
} | |
Validar.prototype.mesInteger = function( valor ){ | |
var mes; | |
switch( valor ){ | |
case 'Jan': | |
mes = "01"; | |
break; | |
case 'Feb': | |
mes = "02"; | |
break; | |
case 'Mar': | |
mes = "03"; | |
break; | |
case 'Apr': | |
mes = "04"; | |
break; | |
case 'May': | |
mes = "05"; | |
break; | |
case 'Jun': | |
mes = "06"; | |
break; | |
case 'Jul': | |
mes = "07"; | |
break; | |
case 'Aug': | |
mes = "08"; | |
break; | |
case 'Sep': | |
mes = "09"; | |
break; | |
case 'Oct': | |
mes = "10"; | |
break; | |
case 'Nov': | |
mes = "11"; | |
break; | |
case 'Dec': | |
mes = "12"; | |
break; | |
} | |
return mes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment