zoukankan      html  css  js  c++  java
  • js身份证验证,二代身份证,大陆,权重验证,正规

    ---------话不多说,直接复制即用。。。-------
    function regIdCard(idcode) {
      const weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
      const check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
      const idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
      const format = idcard_patter.test(idcode);
      const seventeen = idcode.substring(0, 17);
      let num = 0;
      for (let i = 0; i < seventeen.length; i++) {
        num = num + seventeen[i] * weight_factor[i];
      }
      return idcode[17] === check_code[num % 11] && format ? true : false;
    }
  • 相关阅读:
    17、静态链表
    16、约瑟夫问题
    15、循环链表
    9、插入排序
    14、企业链表
    13、单向链表
    12、顺序表的顺序存储结构
    11、归并排序
    10、快速排序
    原型模式
  • 原文地址:https://www.cnblogs.com/qiyc/p/11812626.html
Copyright © 2011-2022 走看看