Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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: testemail@t.com is not valid.

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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,}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading