各种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;
	}
}

  

转载于:https://www.cnblogs.com/gubook/p/5673580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值