正则验证:
reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;通过身份证号获取性别:
getSex(idCard) { var sexStr = ''; if (parseInt(idCard.slice(-2, -1)) % 2 == 1) { sexStr = '男'; } else { sexStr = '女'; } return sexStr; },通过身份证号获取出生年月:
getBirth(idCard) { var birthday = ''; if (idCard != null && idCard != '') { if (idCard.length == 15) { birthday = '19' + idCard.slice(6, 12); } else if (idCard.length == 18) { birthday = idCard.slice(6, 14); } birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-'); //通过正则表达式来指定输出格式为:1990-01-01 } return birthday; },身份证输入立即美化
// 输入身份证搜索 searchChange(){ this.searchValue = this.searchValue.replace(/[^\d^X^x^\s]/g,''); if(this.searchValue.replace(/\s/g, '').length >= 7 && this.searchValue.replace(/\s/g, '').length<15){ this.searchValue = this.searchValue.replace(/\s/g, '').slice(0, 6) + ' ' + this.searchValue.replace(/\s/g, '').slice(6); }else if(this.searchValue.replace(/\s/g, '').length >= 15){ this.searchValue =this.searchValue.replace(/\s/g, '').slice(0, 6) + ' ' + this.searchValue.replace(/\s/g, '').slice(6,14)+ ' ' + this.searchValue.replace(/\s/g, '').slice(14); } this.searchValue =this.searchValue.trim(); },?