身份证正则表达式

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

  var idcard = 336767199903037878

  if(idcardReg.test(idcard)) {

    //合法

  }

  

  //vue验证

  validId_card: function(id_card) {
    var re = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$/;
    return re.test(id_card);
  },

posted @ 2019-07-17 14:27  执笔画浮尘·  阅读(339)  评论(0编辑  收藏  举报