[js]js的表單驗證
阿新 • • 發佈:2018-10-15
bmi 判斷 註意 允許 電話 ret eth 表單提交 turn
http://uule.iteye.com/blog/2183622
表單驗證類
<form class="form" method="post" id="form" onsubmit="return checkForm(this)" action=""> 電話號碼:<input id="tel" type="text" maxlength="11" name="tel"/> <button type="submit" name="submit" value="提交"/> </form>
function checkForm(o){
var re=/^(13[0-9]{9})|(15[89][0-9]{8})$/;
if(!re.test(o.tel.value)){
alert('請輸入正確的手機號碼。');
return false;
}
}
知識點
function submitFun(){ //邏輯判斷 return true; //允許表單提交 //邏輯判斷 return false;//不允許表單提交 } <form onsubmit="reture submitFun();"></form> //註意此處不能寫成 onsubmit="submitFun();"否則將表單總是提交
[js]js的表單驗證