Skip to content

Instantly share code, notes, and snippets.

@BenjaminGuV
Created May 28, 2012 11:24
Show Gist options
  • Save BenjaminGuV/2818641 to your computer and use it in GitHub Desktop.
Save BenjaminGuV/2818641 to your computer and use it in GitHub Desktop.
validar datos con jquery prototype
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