日期:2014-05-17  浏览次数:20395 次

js 验证各种格式类型的正则表达式
今天在做项目的时候写的,留着以后用。多谢指教!!!

    <script src="scripts/jquery-1.4.1.js" type="text/javascript"></script>  
        <script language="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)  
            };  
            /** 
            * @return 若符合对应的格式,返回true,否则返回false 
            */  
            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 必须为数字且不能有中文  
   &nbs