莫大人

js前台数据校验

1.脚本

	Validator = {
			exp:{
				numWord:/^[A-Za-z0-9]+$/, //数字或字母
				numWordM:/^[\-]*[A-Za-z0-9]+$/, //数字或字母可为负数
				letter:/^[A-Za-z]+$/, //字母
				chinese:/^[\u4E00-\u9FA5\uF900-\uFA2D]+$/,
				numberReg:/^[0-9]+$/,//数字格式 只能是0到9的数字 eg:92
				wordReg:/^(\w|[\u4E00-\u9FA5])*$/,//中文,字母,数字
				wordRegAnd_:/^(\w|[\u4E00-\u9FA5\-])*$/,//中文,字母,数字,下划线
				numberFt:/^[0-9]+.?[0-9]*$/,   //验证是数字格式,eg:1.11 
				numberFtMark:/[0-9.]+/,   //验证是数字格式,eg:1.11.234
				chineseMark:/[\u4E00-\u9FA5\uF900-\uFA2D.\-\(\)]+/,//中文,字母,数字,加入括号
				mobilePhone:/(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/,
				email:/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/
			},
			check:function(v,exp,msg){
				console.info(v+","+exp+","+msg);
				try{
					console.info(exp.test(v));
					if(!exp.test(v)){
						Jmts.warnTips(msg);//警告框
						return false;
					}
				}catch(e){
					return false;
				}
				return true;
			},
			checkNumWord:function(v,msg){
				
				return Validator.check(v,Validator.exp.numWord,msg);
				
			},
			checkNumWordM:function(v,msg){
				
				return Validator.check(v,Validator.exp.numWordM,msg);
				
			},
			checkChinese:function(v,msg){
				
				return Validator.check(v,Validator.exp.chinese,msg);
				
			},
			checkChineseMark:function(v,msg){
				
				return Validator.check(v,Validator.exp.chineseMark,msg);
				
			},
			checkNumberFt:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.numberFt,msg);
				
			},
			checkNumberFtMark:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.numberFtMark,msg);
				
			},
			checkNumber:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.numberReg,msg);
				
			},
			checkWord:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.wordReg,msg);
				
			},
			checkWordAnd_:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.wordRegAnd_,msg);
				
			},
			checkLetter:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.letter,msg);
				
			},
			checkMobilePhone:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.mobilePhone,msg);
				
			},
			checkEmail:function(v,msg){ 
				
				return Validator.check(v,Validator.exp.email,msg);
				
			},
			isNull:function(v){
				//如果不为空,那么返回 false
				if(v == null || v == undefined || v == ''){
					return true;
				}else{
					return false;
				}
			}
	};
	

  

 

2.使用

onblur="Validator.isNull(this.value)||Validator.checkNumWordM(this.value,'资金流向编号只能是数字或字母!');"

  

posted on 2017-01-11 17:09  莫大人  阅读(274)  评论(0编辑  收藏  举报

导航