<form action="" method="post" onsubmit="return checkForm(this)">
<input id="p_tel" type="text" name="p_tel" />
<input id="p_cardid" type="text" name="p_cardid" />
<button type="submit"> 查詢</button>
</form>
function checkForm(){
var phone = document.getElementById('p_tel').value;
var cardid=document.getElementById('p_cardid').value;
if(phone==""&&cardid==""){
alert("請輸入手機號和身份證號!");return false;
}else if(phone==""){
alert("請輸入手機號!");return false;
}else{
if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
alert("手機號碼有誤,請重新輸入");
return false;
}
if(cardid==""){
alert("請輸入身份證號!");return false;
}
}
if(!(/^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/.test(cardid))){
alert("身份證號有誤,請重新輸入");return false;
}
}