最新实用常见表单判断代码

- 作者:流年 -

最新实用常见表单判断代码

=====html示例=====

<form action="/plus/diy.php" name="formid" method="post" class="wfform layui-form" onsubmit="return validateform()"   target="_top">
<input type="text" name="wfname" lay-verify="name" placeholder="请填写姓名" class="input-text">
<input type="text" name="wfmob" id="wfmob" lay-verify="mob" placeholder="请填写手机号码" class="input-text">
<label class="wfform-label">所在地区</label>
<div class="wfform-opt area">
<span class="wfprovince"><select id="wfprovince" name="wfprovince" lay-verify="province" class="select" lay-ignore><option value="">请选择省</option></select></span>
<span class="wfcity"><select id="wfcity" name="wfcity" lay-verify="city" class="select" lay-ignore><option value="">请选择市</option></select></span>
<span class="wfarea"><select id="wfarea" name="wfarea" class="select" lay-ignore><option value="">请选择区</option></select></span>
</div>
<textarea name="wfguest" placeholder="请填写补充说明" class="textarea">请尽快安排发货,送货之前手机联系,谢谢!</textarea>
<button id="wfsubmit">立即提交订单</button>
</form>
 

=====js======

<script>
function validateform() {
    var x = document.forms["formid"]["wfname"].value;
    if (x == null || x == "") {
        alert("请您输入姓名");
        return false;
    }
 
  var wfmob = document.forms["formid"]["wfmob"].value;
var re =  /^1[3|4|5|7|8]\d{9}$/;
if (!re.test(wfmob)) {
alert("请输入正确11位手机号码!");
   return false;
      
}
 
    var value = document.forms["formid"]["wfprovince"].value;
    if (value=="") {
        alert("请选择省份");
        return false;
    }
 
    var value = document.forms["formid"]["wfcity"].value;
    if (value=="") {
        alert("请选择城市");
        return false;
    }
 
    var value = document.forms["formid"]["wfarea"].value;
    if (value=="") {
        alert("请选择地区");
        return false;
    }
 
 
    var x = document.forms["formid"]["wfaddress"].value;
    if (x == null || x == "") {
        alert("请填写详细地址");
        return false;
    }  
 
}
</script>