I have created a regex for email validation which will check the email is in proper format or not.

Regular expression for the email is


but when i am putting an email address like [email protected]

this regex expression is not working

How can i solve this issue


1 Answer 1


Your regular expression doesn't do what you think it does. ., by itself, matches any character, not just a .. You need to escape it to specify a literal period. Also, note that emails are a lot more complicated than you think they are; see this answer for a current regular expression that should match all possible valid emails. Translated to Apex, it looks like:

static Pattern emailPattern = Pattern.compile('(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])');
public static Boolean isValidEmail(String email) {
    return emailPattern.matcher(email).matches();

Not the answer you're looking for? Browse other questions tagged .