input表單手機號、身份證號驗證


<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;
}
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM