【问题标题】:How to validate an email filed on key press如何验证在按键上提交的电子邮件
【发布时间】:2015-09-17 07:24:14
【问题描述】:

在我的应用程序中,我想验证在按键上提交的电子邮件文本,但是如何做到这一点我已经在按键上使用了数字验证。就像我发布我所做的一样

$("#start-date").keypress(function (e) {
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
       $(".errmsg").html("Digits Only").show().fadeOut(3000);
               return false;
    }
   });


<input id="start-date" type="text" name="start-date"><span class="errmsg"></span>

.errmsg {
color: red;
font-weight: bold;
}

上面的代码工作正常。

但我想像这样验证我的电子邮件字段

<aui:input inlineField="true" label="" name="interviewCC" id="interviewCC" size="45" value=""></aui:input>

这个字段我想用电子邮件验证来验证,怎么做,请有人帮忙,提前谢谢

【问题讨论】:

标签: jquery validation email


【解决方案1】:

试试这个:-

    $('#youremailfield').on('keypress', function() {
    var re = /([A-Z0-9a-z_-][^@])+?@[^$#<>?]+?\.[\w]{2,4}/.test(this.value);
    if(!re) {
     $(".errmsg").html("Wrong Email").show().fadeOut(3000);
   } else {
     $(".errmsg").hide();
  }
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    相关资源
    最近更新 更多