[js]js的表单验证

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();"否则将表单总是提交  

猜你喜欢

转载自www.cnblogs.com/iiiiiher/p/9790188.html