0

I need a regex for email that allows uppercase and lowercase and I want to validate with jquery .match(). Right now I have this working for lowercase only.

^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$

I'd like one for UC and LC or a combo. Thanks for your help.

amespower
  • 907
  • 1
  • 11
  • 25

4 Answers4

2
function validateEmail($email) {
  var emailRegex = /^[a-zA-Z]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
  if (!emailRegex.test( $email )) {
    return false;
  } else {
    return true;
  }
}

You can use this like:

if( !validateEmail("LowUp@gmail.com")) { /* Code for an invalid emailaddress */ }

Resource: https://stackoverflow.com/a/9082446/4168014

Community
  • 1
  • 1
LetsCode
  • 82
  • 8
1

Ran across this when looking for a regex for uppercase and lowercase letters in an email, so wanted to update this question with an answer that worked for me since the others had some limitations.

^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*(\+[a-zA-Z0-9-]+)?@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$

This will allow for .'s, numbers, lowercase, and uppercase letters in an email with no limit of characters after the '@' sign.

Luke
  • 648
  • 7
  • 15
0

regex

 "^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([A-Za-z]{2,6}(?:\\.[A-Za-z]{2,6})?)$"

Reg expression also works when do we work with capital letters.

karan
  • 3,319
  • 1
  • 35
  • 44
0
public class EmailValidator {

    public static final String EMAIL_REGEX_PATTERN = "^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([A-Za-z]{2,6}(?:\\.[A-Za-z]{2,6})?)$";
    // static String emailId = "GAVIN.HOUSTON@TRANSPORT.NSW.au";
    // static String emailId = "GAVIN.HOUSTON@transport.gov.nsw.au";
    static String emailId = "ap.invoices@sydney.edu.au";

    public static void main(String[] args) {
        System.out.println("is valid email " + isValidEmail(emailId));
    }

    public static boolean isValidEmail(final String email) {
        boolean result = false;
        if (email != null) {
            Pattern pattern = Pattern.compile(EMAIL_REGEX_PATTERN);
            Matcher matcher = pattern.matcher(email);
            result = matcher.matches();
        }
        return result;
    }
}
Enigo
  • 3,685
  • 5
  • 29
  • 54