zoukankan      html  css  js  c++  java
  • 各种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;
    	}
    }
    

      

  • 相关阅读:
    HDU5032 Always Cook Mushroom(树状数组&&离线)
    vue proxyTable
    vue-bus 组件通信插件
    gulp 静态资源版本控制
    js运算【按位非】~
    JS 的引用赋值与传值赋值
    手机端取消长按选中
    无刷新URL 更新
    移动端设计稿尺寸(微信端)
    4105: [Thu Summer Camp 2015]平方运算
  • 原文地址:https://www.cnblogs.com/gubook/p/5673580.html
Copyright © 2011-2022 走看看