javascript検証例3

3105 ワード

/**
 *   id  name,className       ;
 * @param options
 */
CheckOut.getField = function (options){
	this.field = null;
	if(options.id!=null && options.id!="" && options.id!=undefined){
		this.field = jQuery("#"+options.id);
	}
	if(options.name!=null && options.name!="" && options.name!=undefined){
		this.field = jQuery("*[name='"+options.name+"']");
	}
	if(options.className !=null && options.className!="" && options.className!=undefined){
		this.field = jQuery("."+options.className);
	}
	return this.field;	
};

/**
 *           ;
 * @param options
 */
CheckOut.validateType = function(){
	//        ;
	this.addValidateType=function(validateEntity){
		validTypeArray.push(validateEntity);
	};
	
	//       ;
	this.addValidateType(new ValidateEntity("CHECKOUT_NUMBER",function(value,param){
		var paraArray =new CheckOut.ParseArray(param);
		var paramArray = paraArray.getArrayParam();
		var textVal = value.val();
		var result = false;
		if(textVal.length>=parseInt(paramArray[0]) && textVal.length<= parseInt(paramArray[1])){
			var re = /^([0-9])+$/;
			result =  re.test(value.val());
		}
		CheckOut.setImagePosition(value,result,null);
		return result;
	}));
	
	//    ;
	this.addValidateType(new ValidateEntity("CHECKOUT_LENGTH_RANGE",function(value,param){
		var paraArray =new CheckOut.ParseArray(param);
		var paramArray = paraArray.getArrayParam();
		var txtValue =  value.val();
		if(txtValue.length>=parseInt(paramArray[0]) && txtValue.length <=parseInt(paramArray[1])){
			CheckOut.setImagePosition(value,true,null);
			return true;
		}else{
			CheckOut.setImagePosition(value,false,null);
			return false;
		}
	}));
	
	//      ;
	this.addValidateType(new ValidateEntity("CHECKOUT_MOBILE_NUMBER",function(value,param){
		var txtValue =  value.val();
		var expression = /^13[0-9]{1}[0-9]{8}$|^15[012356789]{1}[0-9]{8}$|^18[0256789]{1}[0-9]{8}$/;
		
		var result =  txtValue.length==11 && expression.test(txtValue);
		CheckOut.setImagePosition(value,result,null);
		return result;
	}));
	
	//  validTypeArray    ;
	this.getValidTypeArray = function(){
		return validTypeArray;
	};
	
	//  key      ;
	this.getValidTypeByKey = function(key){
		if(key!=null && key!="" && key != undefined){
			var parse =  new CheckOut.ParseArray(key);
			key = parse.getValidateTypeName();
			for(var i = 0;i<validTypeArray.length;i++){
				if(key==validTypeArray[i].getKey){
					return validTypeArray[i];
				}
			}
		}
		return null;
	};
};