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 shantanu0076@abc.abcedf.com

this regex expression is not working

How can i solve this issue

closed as off-topic by Dave Humm, glls, Derek F, battery.cord, David Reed Aug 24 '18 at 13:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to Salesforce are off-topic here, but can be asked on Stack Overflow." – Dave Humm, glls, Derek F, battery.cord, David Reed
If this question can be reworded to fit the rules in the help center, please edit the question.


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 or ask your own question.