var preg_sfz1 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; var preg_sfz2 = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/; var id_card = document.querySelector("input[name='id_card']").value; if(!(preg_sfz1.test(id_card) || preg_sfz2.test(id_card))) { alert("身份证号码有误"); return false; } //document.querySelector() 获取元素elm对象
if(!preg_match('/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/', $user_card_num)&& !preg_match('/^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/', $user_card_num)){ $results = array('code'=>'-1', 'data'=>'','message'=>urlencode('身份证格式错误!')); exit(urldecode($json->encode($results))); }