各种js验证规则

/*各类验证lbh*/
var CheckInput = function(ele){
	this.eles = $(ele);
	this.ele = [];
	var len = this.eles.length;
	if(len == 0 ){
		return false;
	}else if(len == 1){
		this.ele = this.eles;
	}else{
		this.ele = this.eles.eq(0);
	}
	this.get_value = function(){
		var tagname = this.ele[0].tagName.toUpperCase;
		if( tagname == 'INPUT' || tagname == 'TEXTAREA'){
			return this.ele.val().trim();
		}else{
			return this.ele.html().trim();
		}
	}
};

CheckInput.prototype = {
	is_email : function(){
		return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.get_value()) ? true : false;
	},
	is_not_null : function(){
		return !this.get_value() ? true : false;
	},
	is_intnumber : function(){
		return /^[1-9][0-9]*$/.test(this.get_value()) ? true : false;
	},
	is_age : function(){
		var val = parseFloat(this.get_value());
		return val >= 0 && val <= 150 ? true : false;
	},
	is_phone_number : function(){
		return /^[1-9][8,3,5][0-9]{9}$/.test(this.get_value()) ? true : false;
	},
	is_number : function(){
		/*匹配正整数或正小数*/
		return /(^0\.[0-9]*$)|(^[1-9][0-9]*\.[0-9]*$)/.test(this.get_value()) ? true : false;
	},
	is_month : function(){
		return /^(0?[1-9]|1[0-2])$/.test(this.get_value()) ? true : false;
	},
	is_day : function(){
		return /^((0?[1-9])|((1|2)[0-9])|30|31)$/.test(this.get_value()) ? true : false;
	},
	is_vaicode : function(){
		/*六位数字验证码*/
		return /^[0-9]{6}$/.test(this.get_value()) ? true : false;
	},
	is_idcart : function(){
		return /^\d{15}|\d{18}$/.test(this.get_value()) ? true : false;
	}
}

  

posted @ 2016-07-15 14:51  gubook  阅读(941)  评论(2编辑  收藏  举报