Regex pattern issue with single character

Advertisements

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: testemail@t.com 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: testemail@tt.com 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,}

Leave a ReplyCancel reply