0

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.

Yupi
  • 4,402
  • 3
  • 18
  • 37
  • 3
    [Why craft your own](https://stackoverflow.com/a/201378)? – Ivar May 02 '23 at 11:32
  • 1
    Your pattern enforces at least ***two*** characters. That is because `([A-Za-z0-9]+[.-]?)+` will require at least one, and followed by `[A-Za-z0-9]+` which requires another character – Tomerikoo May 02 '23 at 11:36

1 Answers1

1

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