- 校验用户名可以为中文,英文字母,数字及下划线组成,长度3-15位
let regex = /^[\u4E00-\u9FA5\uF900-\uFA2D|\w]{3,15}$/;
- 密码强度 6-16个字符,不包含空格,必须包含数字,字母或字符至少两种
let regex = /(?!.*\s)(?!^[\u4e00-\u9fa5]+$)(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,16}$/
let regex=/^[1][3,4,5,6,7,8,9][0-9]{9}$/
let regex = /^\s*$/g;
export function testID(id) {
// 1 "验证通过!", 0 //校验不通过
let format = /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/;
if (!format.test(id)) {
return false
}
//区位码校验
//出生年月日校验 前正则限制起始年份为1900;
let year = id.substr(6, 4), //身份证年
month = id.substr(10, 2), //身份证月
date = id.substr(12, 2), //身份证日
time = Date.parse(month + '-' + date + '-' + year), //身份证日期时间戳date
now_time = Date.parse(new Date()), //当前时间戳
dates = (new Date(year, month, 0)).getDate(); //身份证当月天数
if (time > now_time || date > dates) {
// this.$toast('出生日期不合规');
return false
}
//校验码判断
let c = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //系数
let b = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); //校验码对照表
let id_array = id.split("");
let sum = 0;
for (let k = 0; k < 17; k++) {
sum += parseInt(id_array[k]) * parseInt(c[k]);
}
if (id_array[17].toUpperCase() != b[sum % 11].toUpperCase()) {
return false
}
return true
}