一个正则表达式的小用!

 现在这是一个正则表达式的小应用!

如下是正则表达式的js

function Validate(){
    this.number = /^/d+$/;
    this.integer = /^[-/+]?/d+$/;
    this.double = /^[-/+]?/d+(/./d+)?$/;
    this.phone = /^((/(/d{3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}$/;
--  (前三位为数字带括号|三位数字-)最多有一个  (0 数字两到三个|0 数字两到三个-)最多现一次
     1-9为开头 数字六到七位         这是一个完整的固定电话号码验证           --
    this.mobile = /^((/(/d{3}/))|(/d{3}/-))?13/d{9}$/;
    this.email = /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/;  -- /w 为数字、字母、下划线         --
    this.qq = /^[1-9]/d{4,8}$/;
    this.idCard = /^/d{15}(/d{2}[A-Za-z0-9])?$/;
    this.english = /^[A-Za-z]+$/;
    this.chinese = /^[/u0391-/uFFE5]+$/;   -- 汉字在U码中的取值范围 --
    this.date = /^/d{4}-[01]/d{1}-([0-2]/d{1}|31)$/;
    this.url=/^http:[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*$/;
}

Validate.prototype.test=function(reg,str){
    if(reg.test(str)){
        return true;
    }
    return false;
}

Validate.prototype.isEmpty=function(str){
    if(str=="" || str==null){
        return true;
    }
    return false;
}

Validate.prototype.isNumber=function(str){
    return this.test(this.number,str);
}

Validate.prototype.isInteger=function(str){
    return this.test(this.integer,str);
}

Validate.prototype.isDouble=function(str){
    return this.test(this.double,str);
}

Validate.prototype.isPhone=function(str){
    return this.test(this.phone,str);
}

Validate.prototype.isMobile=function(str){
    return this.test(this.mobile,str);
}

Validate.prototype.isEmail=function(str){
    return this.test(this.email,str);
}

Validate.prototype.isQQ=function(str){
    return this.test(this.qq,str);
}

Validate.prototype.isIdCard=function(str){
    return this.test(this.idCard,str);
}

Validate.prototype.isEnglish=function(str){
    return this.test(this.englist,str);
}

Validate.prototype.isChinese=function(str){
    return this.test(this.chinese,str);
}

Validate.prototype.isDate=function(str){
    return this.test(this.date,str);
}

Validate.prototype.isUrl=function(str){
    return this.test(this.url,str);
}

 

用它的时候这样写:页面上如下:

<script src="Validate.js"></script>
<script>
    var validate=new Validate();
    var str="aaaa";
    if(validate.isDate(str)){
        alert("true");
    }else{
        alert("false");
    }
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值