- Vue.prototype.$checkIdCard = function(idCard){
- idCard = idCard.toUpperCase();
- let city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",
- 33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",
- 50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",
- 81:"香港",82:"澳门",91:"国外"};
- if (len !== 15 && len !== 18){
- _this.$toast.error('身份证号长度不正确!');
- if (!(/(^\d{15})|(^̲\d{17}([0-9]|X))/.test(idCard))) {
- _this.$toast.error('身份证号格式错误!');
- if (!city[idCard.substr(0,2)]){
- _this.$toast.error('身份证号地址码不正确!');
- re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
- let arrSplit = idCard.match(re);
- let birth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' +arrSplit[4]);
- let isBirth = (birth.getYear() === Number(arrSplit[2])) && ((birth.getMonth() + 1) === Number(arrSplit[3])) && (birth.getDate() === Number(arrSplit[4]));
- _this.$toast.error('身份证号出生日期不对!');
- re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
- let arrSplit = idCard.match(re);
- let birth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" +arrSplit[4]);
- let isBirth = (birth.getFullYear() === Number(arrSplit[2])) && ((birth.getMonth() + 1) === Number(arrSplit[3]))
- && (birth.getDate() === Number(arrSplit[4]) && (birth.getTime()<new Date().getTime()));
- _this.$toast.error('身份证号出生日期不对!');
- let arrInt = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
- let arrCh = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
- for (i = 0; i < 17; i++) {
- nTemp += idCard.substr(i, 1) * arrInt[i];
- valnum = arrCh[nTemp % 11];
- if (valnum !== idCard.substr(17, 1)) {
- _this.$toast.error('身份证号校验码不正确!');
- bbd = bbd.getFullYear() + '-' + Number(bbd.getMonth() + 1) + '-' + bbd.getDate();
- let arr_fix = bbd.split('-');
- if(arr_fix[1].length == 1){
- arr_fix[1] = '0' + arr_fix[1];
- if(arr_fix[2].length == 1){
- arr_fix[2] = '0' + arr_fix[2];
- bbd = arr_fix[0] + '-' + arr_fix[1] + '-' + arr_fix[2];
- sex = idCard.charAt(idCard.length - 2)
- sex = idCard.charAt(idCard.length - 1)
posted @
2021-03-16 16:11
未几
阅读(
129)
评论()
收藏
举报