0

I have a regex for email validation in my javascript file as below

^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$

Its working for everything except the below condition

test.regex@gmail.com1 - Not getting validated since i put 1 after .com .

Please help to resolve this validation using the above regex as i dont want to go for some new regex .I want to know the exact error in the above question which will help to track this kind of validation errors in future.

I am quite new in javascript/jquery . Please help me to resolve the above issue .

Viku
  • 2,845
  • 4
  • 35
  • 63
  • 4
    Validating the domain with Regex is difficult (if not impossible) because there is no single pattern to match them. The only workable solution is to hold a dictionary of all the possible TLDs and match against them. Personally, I wouldn't bother. A better pattern to use when validating email addresses is to send a confirmation email with a link to mark the account as confirmed. – Rory McCrossan Feb 10 '15 at 14:17
  • 2
    Why is there a requirement that your regex be fixed? Wouldn't a standard "valid email regex" work? That is an odd restriction. – Bill Gregg Feb 10 '15 at 14:18
  • @BillGregg : Because i want to know where exactly its getting failed so that i wont repeat the mistake in future . – Viku Feb 10 '15 at 14:28
  • @cerbrus : How can you mark it as duplicate ? Look at the description i have asked . I dont need any other regex . I just want to correct my existing one . And the marked answer for the query you have mentioned also not working for all scenarios. – Viku Feb 10 '15 at 14:56

0 Answers0