身份证正则验证:
const pattern = /(^d{8}(0d|10|11|12)([0-2]d|30|31)d{3}$)|(^d{6}(18|19|20)d{2}(0d|10|11|12)([0-2]d|30|31)d{3}(d|X|x)$)/
根据身份证截取出生日期
<script> function getBirthdayFromIdCard (idCard) { var birthday = '' if (idCard != null && idCard !== '') { if (idCard.length === 15) { birthday = '19' + idCard.substr(6, 6) } else if (idCard.length === 18) { birthday = idCard.substr(6, 8) } birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-') } return birthday } console.log( getBirthdayFromIdCard('140321199909100911')); //1999-09-10 </script>