js 验证各种格式类型的正则表达式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huoshichao/article/details/82971355

转载地址:https://blog.csdn.net/tp851716/article/details/43451247?utm_source=copy

<"scripts/jquery-1.4.1.js" type="text/javascript">  
        "javascript" type="text/javascript">  
              
            var Regexs = {  
                email: (/^[0-9a-z][0-9a-z-_.]+@([0-9a-z][0-9a-z-]*.)+[a-z]{2,}$/i),//邮箱  
                phone: (/^0[0-9]{2,3}[2-9][0-9]{6,7}$/),//座机手机号码  
                ydphpne: (/^((13[4-9])|(15[012789])|147|182|187|188)[0-9]{8}$/),//移动手机号码  
                allphpne: (/^((13[0-9])|(15[0-9])|(18[0-9]))[0-9]{8}$/),//所有手机号码  
                ltphpne: (/^((13[0-2])|(15[56])|(186)|(145))[0-9]{8}$/),//联通手机号码  
                dxphpne: (/^((133)|(153)|(180)|(189))[0-9]{8}$/),//电信手机号码  
                url: (/^http://([0-9a-z][0-9a-z-]*.)+[a-z]{2,}(:d+)?/[0-9a-z%-_/.]+/i),//网址  
                num: (/[^0-9]/),//数字  
                cnum: (/[^0-9a-zA-Z_.-]/),  
                photo: (/.jpg$|.jpeg$|.gif$/i),//图片格式  
                row: (/n/ig)  
            };  
              
            function chkFormat(str, ftype) {  
                var nReg = Regexs[ftype];  
                if (str == null || str == "") return false; //输入为空,认为是验证通过  
                if (ftype == 'num') {  
                    if (!nReg.test(str) && !chkChinese(str)) {//10.23 tenfy 必须为数字且不能有中文  
                        return true;  
                    } else {  
                        return false;  
                    }  
                }  
                if (!nReg.test(str)) {  
                    return true;  
                } else {  
                    return false;  
        
                }  
            };  
            function chkChinese(s) {  
                for (var i = 0; i < s.length; i++) {  
                    if (s.charCodeAt(i) > 255) return true;  
                }  
                return false;  
            };  
          

猜你喜欢

转载自blog.csdn.net/huoshichao/article/details/82971355
今日推荐