js1

2021-07-08 15:04

阅读:416

标签:最大   idf   null   event   rtti   手机   amp   title   substr   

/*说明
-------------------------------------------------------------------------------------
函数名:InputCheck(InputEle)
InputEle 为要检测的元素,这个元素的class为格式化信息:输入类型|必要性|最小长度|最大长度
返回:message and false or true
格式化信息:
			输入类型:
				txt	1-文本(不能包含非法字符)
				num	2-数字(0123456789)
				val	3-数值(0123456789.)
				tel	4-电话号码(020-83559078)
				mob	5-手机号码(11位0123456789)
				dat	6-日期(YYYY-MM-DD)
				tim	7-时间(HH:MM:SS)
				sel	8-选择(值为-1时表示未选择)
				img 9-图像文件路径
				eml 10-电子邮箱格式
				idc	11-身份证
				
			必要性:	
				y	1-必要
				n 	0-不一定
			最小长度:0
			最大长度:2147483647
			
eg: 表示输入为文本,且是必要的,最小长度为0,最大长度为10
---------------------------------------------------------------------------------
*/

function InputCheck(InputEle){
	
	var ClassName=new String();//信息格式化:输入类型|必要性|最小长度|最大长度
	var availChar=new String();
	var invalChar=new String();
	var InputValue=new String();
	var alertTitle=new String();
	var i=0;
	try{ClassName=InputEle.myClass;}catch(e){return;}
	
	if (typeof ClassName == "undefined" || ClassName == null) return true;
	

	var arr=ClassName.split("|");
	
	var InputType="txt";    //默认为文本	
	var Need="n";		//默认无限制
	var minLen=0;		//默认无限制
	var maxLen=0;		//默认无限制
	var minVal="err";	
	var maxVal="err";

	if (InputEle.disabled==true){
		return true ;
	}	
		
	if (arr.length>0){
		InputType=arr[0];
	}	
	if (arr.length>1){
		Need=arr[1];
	}	
	if (arr.length>2){
		minLen=arr[2];
	}
	if (arr.length>3){
		maxLen=arr[3];
	}
	if (arr.length>4){
		minVal=arr[4];
	}
	if (arr.length>5){
		maxVal=arr[5];
	}

	InputValue = InputEle.value;
	alertTitle = InputEle.title;
	
	//必要性检测
	if (Need=="y"){
		if(InputValue.length ==0){
			alert(alertTitle + " 不能为空" );
			try {
			    InputEle.focus();
			    InputEle.select();
			}catch(ex){}
			return false;
		}
	}
	
	if(InputValue.length>0){//存在值时检测最小长度,最大长度
		if(minLen!=0&&InputValue.length maxLen){
			alert(alertTitle + " 不能大于 " + maxLen.toString() +" 位");
			InputEle.focus();
			InputEle.select();
			return false;
		}
	}
	
	switch(InputType){//输入类型
	case "txt"://1-文本(不能包含字符"‘%()")
		/*invalChar="=‘~!@#$%^&*()";
		for(i=0;i=0){
				alert (alertTitle + " 不能包含字符 " +invalChar);
				InputEle.focus();
				InputEle.select();
				return false;
			}
		}*/
		return true;
		
	case "num"://2-数字(0123456789)
		availChar="0123456789";
		for(i=0;i0){
			alert (alertTitle + " 必须大于" +minVal.toString());
			InputEle.focus();
			InputEle.select();
			return false;
		}
		if(maxVal!="err"&&parseFloat(InputValue)>parseFloat(maxVal)&&InputValue.length>0){
			alert (alertTitle + " 必须小于" +maxVal.toString());
			InputEle.focus();
			InputEle.select();
			return false;
		}
		return true;
		
	case "tel"://电话号码(020-83559078)
		availChar="0123456789-";
		for(i=0;i12 || ObjMonthLastDate.getDate() || ObjDate24){
					alert ("时间格式为HH:MM:SS")
					InputEle.focus();
					InputEle.select();
					return false;
				}
			}
			
			tmp=InputValue.substr(3,2)
			for(i=0;i60){
					alert ("时间格式为HH:MM:SS")
					InputEle.focus();
					InputEle.select();
					return false;
				}
			}
			
			tmp=InputValue.substr(6,2)
			for(i=0;i60){
					alert ("时间格式为HH:MM:SS")
					InputEle.focus();
					InputEle.select();
					return false;
				}
			}
		}
		
		return true;
		
	case "sel"://选择(值为-1时表示未选择)
		if (InputValue==-1){
			alert("必须选择 "+ alertTitle);	
			InputEle.focus();
			//InputEle.select();					
			return false;
		}
		return true;
	
	case "img":// 图像文件
		if (InputValue.length==0){
			return true;
		}
		var img=document.createElement("img") ;
			img.src=InputValue ;
		if (img.fileSize

js1

标签:最大   idf   null   event   rtti   手机   amp   title   substr   

原文地址:http://www.cnblogs.com/systembighunter/p/7096743.html


评论


亲,登录后才可以留言!