Search code examples
regexemail-validation

Regex pattern issue with single character


I have a regex for emails validation and it goes like this:

[A-Z0-9a-z._%+-]+@([A-Za-z0-9]+[.-]?)+[A-Za-z0-9]+\.[A-Za-z]{2,}

But some users with a single letter after the @ character email can not be validated. For instance: [email protected] is not valid.

I'm not sure how to change the regex to allow this validation as well.

By checking it, this part here @([A-Za-z0-9] should already allow setting at least one character after @ but it doesn't. If I put like at least 2 letters then the email is validated. For instance: [email protected] is valid.

Any help is more than welcome.


Solution

  • Maybe you can try this way [A-Z0-9a-z._%+-]+@([A-Za-z0-9]+[.-]?)*[A-Za-z0-9]+\.[A-Za-z]{2,}