zoukankan      html  css  js  c++  java
  • 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(3d|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}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}$/; 

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

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

  • 相关阅读:
    java
    MVC4重复提交数据
    cache
    Nosql
    MVC4重复提交
    PHP Java
    .net performance
    How the Runtime Locates Assemblies
    android
    window.onscroll
  • 原文地址:https://www.cnblogs.com/Zing/p/4381079.html
Copyright © 2011-2022 走看看