Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
JavaScript Email Pattern returning true for invalid format

I'm not going to reinvent the wheel. so after surfing google, (not that much expert in regx stuff) i found below function.

function emailPatternCheck(input){      
   var email= /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return email.test(input); 
 } 

it's supposed to return false for emailPatternCheck('example123@demo.com.com.com') . but getting true.

Could some tell me where should do modification to avoid .com.com.com

Sample input

emailPatternCheck('example123@demo.com') // true, expected
emailPatternCheck('ex_123@demo.com') // true, expected
emailPatternCheck('ex-123@demo.com') // true, expected
emailPatternCheck('#$%#$@demo.com') // false, expected
emailPatternCheck('example@@@asdf.com') // false, expected
emailPatternCheck('example@$%#%.com') // false, expected

emailPatternCheck('example123@demo.com.com.com') should be false not true

Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!