jQuery电子邮件正则表达式

jQuery电子邮件正则表达式

本文介绍了jQuery电子邮件正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个脚本,现在我很难过。我尝试了许多来自Google的Regex并且没有工作,这是我的代码:

I have been developing a script and I'm stumped right now. I have tried many different Regex from Google and non have worked, this is my code:

$(document).ready(function() {
    var email_check = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/;
    num = 0;
    $('#email').focus(function() {
        $('#email_check').show();
        $(this).keyup(function() {
            error = 0;
            var email = $('#email').val();
            num = num+1;
            if(!email_check.test(email)) {
                error = 1;
            }
            if(error == 0) {
                $('#email_check').html('O'+num+email+error);
            }else if(error == 1) {
                $('#email_check').html('X'+num+email+error);
            }
        });
    });
});

任何帮助都很棒,谢谢!

Any help is great, thanks!

推荐答案

设置不区分大小写的标志(i):

Set the case insensitive flag (i):

var email_check = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i;

这篇关于jQuery电子邮件正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 01:32