js验证表单

 <asp:Button ID="Button1" runat="server" Text=" 提 交 " onclick="Button1_Click"  OnClientClick="return check()"   />
function check() {
  if (document.getElementById("txtcompanyname").value == "") {
              alert("请填写企业名称!");
              return false;
          }
   var tel = document.getElementById("txttel").value;
          var p1 = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;

          if (tel == "") {
              alert("请填写电话!");
              return false;
          }
 if (!p1.test(tel)) {
              alert("电话格式错误!");
              return false;
          }
  var mobile = document.getElementById("txtmobile").value;
          var pmobile = /^(\d{11})?$/;
          if (mobile == "") {
              alert("请填写手机!");
              return false;
          }
          if (!pmobile.test(mobile)) {
              alert("手机格式错误!");
              return false;
          }
  var mail = document.getElementById("txtmail").value;
          var pmail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
          if (mail == "") {
              alert("请填写邮箱!");
              return false;
          }
          if (!pmail.test(mail)) {
              alert("邮箱格式错误!");
              return false;
          }
 //下拉列表
 if (document.getElementById("ddlxingzhi").value == "0") {
              alert("请选择所有制性质!");
              return false;
          }
}

你可能感兴趣的:(js)