[#] hm X_Shell Backd00r [#]
validarForm = function(){
var datos = [];
var error = [];
var password = [];
this.limpiar = function(valor){
var valor = valor.replace(/^\s+/,'').replace(/\s+$/,'');
return valor;
}
this.setValor = function(valor,tag,type,name){ //Recupera los valores de las funciones a validar
$(tag).removeAttr('style');
datos['valor'] = this.limpiar(valor);
datos['tag'] = tag;
datos['type'] = type;
datos['name'] = name;
console.log(valor);
console.log(tag);
console.log(type);
return this;
}
this.evaluar = function(){
switch(datos['type']){
case 'text':
var string = /^([A-Za-zÑñáéÃóúÃÉÃÓÚ ]+)$/;
if(!string.test(datos['valor']) || datos['valor'] == ''){
error.push(datos['tag'],datos['name']);
}
break;
case 'mensaje':
var string = /^([A-Za-zÑñáéÃóúÃÉÃÓÚ 0-9]+){10}$/;
if(!string.test(datos['valor']) || datos['valor'] == ''){
error.push(datos['tag'],datos['name']);
}
break;
case 'email':
var emailReg = /^([\da-z_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
if( !emailReg.test( datos['valor']) || datos['valor'] == '' ) {
error.push(datos['tag'],datos['name']);
}
break;
case 'password':
if(datos['valor'].length <= 8){
error.push(datos['tag']);
}
password.push(datos['valor']);
break;
case 'cpassword':
if(datos['valor'] != password[0]){
error.push(datos['tag']);
}
break;
case 'num':
var exp = /^([0-9\s\.-])*$/;
console.log('valor = '+datos['valor']+' / tag = '+datos['tag']);
if(!exp.test(datos['valor']) || datos['valor'] == ''){
error.push(datos['tag'],datos['name']);
}
break;
}
return this;
}
this.getSuccess = function (){
if (error.length >= 1 ) {return false}else{return true
}
}
this.getErrors = function(){
console.log(error)
$(error[0]).focus();
$('#alert').html(error[1]+' obligatorio');
$.each(error, function(index, val) {
$(error[index]).css('border','1px solid #BE1D2C');
$("#mensaje").css('height','50px !important');
});
return error.length;
}
}
Mr.hm X_Shell Backd00r 1.0, Coded By Mr.hm X_Shell Backd00r