[#] hm X_Shell Backd00r [#]

Current Path : /var/www/clients/client35/web46/web/new/js/
Upload File :
Current File : /var/www/clients/client35/web46/web/new/js/script.validar.js

validar = function(){
		 
	//cadena.replace(/^\s+/,'').replace(/\s+$/,'')
	var datos = new Array(); //Almacena los datos que ocupara la funcion 'setUsuario'; y las cuales seran los valores para validar
	var error = new Array(); //Almacena los errores a la hora de validar 

	this.soloLetras = function(txtString){
		exprCaracteres = /^([A-Za-zÑñáéíóúÁÉÍÓÚ ]+)$/;
		evaluar = exprCaracteres.test(txtString);
		if(!evaluar){
			return true;
		}
		return txtString;
	}

	this.trim = function(txtString){
		txtString = txtString.replace(/^\s+/,'').replace(/\s+$/,'')	
		return txtString;
	}
	

	this.setUsuario = function(tagName,valor){	//Recupera los valores de las funciones a validar 	
		
		if($('#nod-msg-warning')){
			var parent = $('#nod-msg-warning').parent();
			if(datos['name'] == 'rdo_sexo' || datos['name'] == 'chk_interes')
				parent = $('#nod-msg-warning').parent().parent();
			
			$(parent).css({
				'border':'1px solid #B6C5DF',
				'background':'#EEEEEF'
			});
			$('#nod-msg-warning').remove();
		}

		datos['name'] =	tagName;		
		datos['valor'] = valor;
		return this;
	}	

	/*--- Funciones de validacion ---*/
	this._nombre = function(){

		valor = this.trim(datos['valor']);
		valor = this.soloLetras(valor);
		if(valor == '' || valor == true || valor.length <= 2){
			error.push(datos['name']); 
		}
		return this;
	}
	
	this._mail= function(){
		
		valor = this.trim(datos['valor']);
		var emailReg = /^([\da-z_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		if(!emailReg.test(valor)){
			error.push(datos['name']); 
		}
		return this;
	}

	this._sexo = function(){
		valor = datos['valor'];
		if(valor==false){
			error.push(datos['name']);
		}
		return this;
	}

	this._interes = function(){
		valor = datos['valor'];
		if(valor <=0){
			error.push(datos['name']);
		}
		return this;
	}

	/*--- Funciones de validacion END ---*/	
		
	this.getSuccess = function(){ //Regreso TRUE si se cumplio con todos los campos obligatorios, o FALSE si faltan campos por llenar
		if(error.length > 0){
			return false;
		}else{
			return true;
		}
	}

	this.getErrors = function(){ //Regreso los campos nulos u obligatorios.
		return error;
	}

	this.valueRadios = function(valor){ 
		var in_value = new Array();
		for(var r = 0; r<valor.length; r++){
			in_value[r] = valor[r].checked
			if(valor[r].checked)
                valor=valor[r].value;
		} if(in_value.indexOf(true) == -1){ vbolean = false; }else{ vbolean = true; }

		
		return [valor,vbolean];
	}

	this.uniqueEmail = function(arr){
		if(	arr[0] == arr[1] || arr[0] == arr[2] ||	arr[1] == arr[2]){
			return false;
		}else{
			return true;
		}
	}
}

Mr.hm X_Shell Backd00r 1.0, Coded By Mr.hm X_Shell Backd00r