常用的Javascript表单正则验证函数

/**
 * 传入一个input对象,自动检测里面的值
 */
function CheckInput(){
		
		this.checkLength=function(obj,len)
		{
			this.value = obj.value;
			var length=6;
			if(len!=null){
				length=len;
			}
			if(this.value.length<length)
			{
				return false;
			}
			return true;
		}
		this.isNotNumber=function(obj)//检测数字,是数返回false,不是数返回true
		{
			this.value = obj.value;
			if(isNaN(this.value)){
				return true;
			}else{
				return false;
			}
		}
		this.haveChinese=function(obj){//检查中文,如果有中文返回true
			this.value = obj.value;
			var reg = /[\u4e00-\u9fa5]/;
			var reg2 = /[^\x00-\xff]/;
			return reg.test(this.value)||reg2.test(this.value);
			
		}
		this.haveIllegalChar=function(obj)//检查特殊字符,有返回true
		{
			this.value = obj.value;
		    var pattern=/[`~!#$%^&*()_+<>?:"{},\/;'[\]]/im;  
		    if(pattern.test(this.value)){  
		        return true;     
		    }     
		    return false;  
		}
		this.isEmpty=function(obj){//检查是否为空,为空返回true
			this.value = obj.value;
			if(this.value.length>0){
				return false;
			}else{
				return true;
			}
		}
		 
		this.isPhoneNum = function(obj)
		{	
			this.value = obj.value;
			var reg = /^1[3|5][0-9]\d{8}$/;
		    return reg.test(this.value);
		}
		
		this.isQQ = function(obj){
			this.value = obj.value;
			var reg = /^[1-9]\d{4,10}$/;
			return reg.test(this.value);
		}
		
		
		this.isEmail = function(obj)
		{	
			this.value = obj.value;
			var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
		    return reg.test($(obj).val());
		}
		
		this.checkSize = function(obj,min,max)
		{	
			this.value = obj.value;
			var myMin=0;
			var myMax=100;
			if(min!=null) myMin=min;
			if(max!=null) myMax=max;
			if(this.value<myMin||this.value>myMax){
				return false;
			}
			else
			{
				return true;
			}
		}
	
	}

你可能感兴趣的:(JavaScript,表单,正则)