js基础-正则处理函数

function RegFn(){
    
}
RegFn.prototype = {
    //移出空白字符
    removeNullStr: function( str ){
        return  str.replace(/\s/g,'');
    },
    diffBrowser:function(){
        var str =  window.navigator.userAgent.toLowerCase();
        console.log( str );
        var reg = /( msie|chrome|firefox|opera|safari)/g;
        return str.match(reg,str)[0];
    },
    checkChinese:function( str ){
        var reg = /^[\u4e00-\u9fa5]+$/g;
        return reg.test( str );
    },
    checkQQ:function( str ){
        var reg = /^[1-9]\d{4,10}$/g;
        return reg.test(str);
    },
    checkUsername:function( str ){
       var reg = /^\w[\w\d]{5,17}$/g;
       return reg.test(str);
    },
    checkPwd:function( str ){
        var reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{6,15}$/g;
        return reg.test(str);
    },
    //身份证格式验证,合法
    checkId:function( str ){
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/g; 
        return reg.test(str);
    },
    //常用手机号码格式验证
    validatePhone: function (str) {
        var reg = /^[1][3,4,5,7,8][0-9]{9}$/g
        return reg.test(str);
    },
     //常用简单邮箱格式验证
     validateEmail: function (str) {
        var reg = /^\w+@[a-z0-9]+\.[a-z]{2,3}$/gi
        return reg.test(str);
    }

    
}

阅读更多

没有更多推荐了,返回首页