处理html5和jquery中的电子邮件验证事件

时间:2014-12-03 05:56:59

标签: jquery html5 validation events

我的页面中有以下电子邮件输入

<input type="email" value="" id="emailId" class="validate[required] text-input">

<input type="submit" value="Submit" onclick="runProgress();" title="Submit" id="submitId">

function runProgress() {
    //After successful validation (how to check this)?

    //code for changing visibility flag of progress popup
    $("#alertcontainer").css("display", "block");
}

我的实现就像当我提交页面时,我显示处理弹出窗口,它使用jquery使我的屏幕变灰。

现在它显示验证错误,但我的jquery函数使我的屏幕变灰。所以我想检查验证错误是否已经出现,然后我不会使我的屏幕变灰。

我正在使用示例代码。我想将此应用于其他验证,如数字和所有。

我可以获得任何标志/功能,表明我的表单中没有验证消息吗?

感谢。

2 个答案:

答案 0 :(得分:0)

这是样本..

 var validator = $('#form').validate({
      rules: {
        email: {
          required: true,
          email: true
        }
      },
      messages: {
        email: ''
      },
      success: function() {
        console.log('success'); // do something here.. here is the success
      },
      highlight: function() {
        console.log('highlight');
      }
    }

答案 1 :(得分:0)

正如您的代码所描述的那样..

 function runProgress() {
        if(!isValidEmailAddress($("#sc_email").val())) (
            $("#alertcontainer").css("display", "block");
          return false;         
       }
        else if($("#customername").val()=='' OR $("#customername").val()==' ') { 
           $("#alertcontainer").css("display", "block");
           return false;         
      }
        else{
          return true; //do something
      }
   }

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
};