表单验证-邮箱验证

邮箱验证

1、使用function函数实现

     注:需要在代码的标签中加入属性:οnblur="loginEmailBlur(this.value)"

 function loginEmailBlur(strEmail) {
            var loginEmail = $.trim($("input[name='email']").val());
            if (loginEmail == null || loginEmail == '邮箱' || loginEmail == "") {
                $(".smtwarning").empty().text("您的邮箱账号忘记输入了");
                
                }
                else{
                    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
                        $(".smtwarning").empty();
                        return true;
                    }
                    else {
                        $(".smtwarning").empty().text("请输入正确的邮箱格式");
                    }
            }
        }

2、在 $(document).ready(function ())中书写

//登录框表单验证
   var $loginEmail = $("input[name='email']");
   var $stmWarning = $(".smtwarning");

   $loginEmail.blur(function () {
       var loginEmail = $.trim($("input[name='email']").val());
       if (loginEmail == null || loginEmail == '邮箱' || loginEmail == "") {
            $stmWarning.empty().text("您的邮箱账号忘记输入了");
       }else {
          if (loginEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
              $stmWarning.empty();
              return true;
           }else {
              $stmWarning.empty().text("请输入正确的邮箱格式");
           }
      }
  });


 

你可能感兴趣的:(js)