js 验证手机号 以及身份证正则表达式

手机号:① /^1(3[0-9]{9}|5[0-35-9][0-9]{8}|7[07][0-9]{8}|8[25-9][0-9]{8})$/

    ② /^1(3\d|5[0-35-9]|7[07]|8[25-9])\d{8}$/

②是①的简写

 

身份证_18: 

function cidInfo(sId) {
                var iSum = 0
                var info = ""
                if (!/^\d{17}(\d|x)$/i.test(sId)) { return false; }
                sId = sId.replace(/x$/i, "a");
                if (aCity[parseInt(sId.substr(0, 2))] == null) { return "Error:非法地区"; }
                sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
                var d = new Date(sBirthday.replace(/-/g, "/"))
                if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return "Error:非法生日";
                for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11)
                if (iSum % 11 != 1) return "Error:非法证号";
         return aCity[parseInt(sId.substr(0, 2))] + "," + sBirthday + "," + (sId.substr(16, 1) % 2 ? "男" : "女")
 }

身份证_15:

 var isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/; 

 

字数限制和只能输入数字验证:

<input  type="text" onkeyup="value=value.replace(/[^\d]/g,'') " maxlength="11">

posted @ 2015-03-31 15:36  朝闲  阅读(310)  评论(0编辑  收藏  举报