Help with email checker - doesn't allow uppercase currently

Hi,

I’m afraid i am not very good with JS so i am hoping that someone can help. I’ve copied a website (with permission) and it uses some JS for checking the email address as follows

 'email': function() {
            var ele = $('#email');
            var label = $('#em-label');
            var patt = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
            if (!patt.test(ele.val())) {
                jVal.errors = true;
                label.addClass('err');
            } else {
                label.removeClass('err');

            }

If i enter my email address with a capital letter it doesn’t allow the form to be submitted and simply just displays a red border. I think this would confuse a lot of users as there is nothing to say it is because there is a capital letter.

I am assuming the ‘patt’ variable is saying only allow certain characters and from what i can see they are a-z in lower case. Is there a way of saying don’t worry about case. Or do i need to add in the uppercase A-Z.

Stabbing in the dark would this work-

var patt = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

any help appreciated

That should work. If it doesn’t work, try:

var patt = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i; // added 'i' after the closing slash to indicate case Insensitive.

HTH,

^ _ ^

1 Like

gave it a try and it worked :slight_smile:

Didn’t want to try without checking it was likely to work as it’s a live site.

When it’s a bit quieter i’ll try the ‘i’ version as that would be useful to know for future applications rather than having to have extra A-Z’s everywhere.

thanks for the quick response.

Glad I could help. To be honest, I’ve been working with RegEx for years and still don’t fully grasp it. It can be a fickle beast, at times.

V/r,

^ _ ^

Oh, and another thing. There is a great site for testing your RegEx code! I love this site.

V/r,

^ _ ^

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.