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

187
Views
Regex to allow up to two dots in email address

I am trying to validate the first part of an email address and I want to allow up to two dots, for example these would be valid:

  • alan@gmail.com
  • alan.smith@gmail.com
  • alan.smith.86@gmail.com

I have tried this regex pattern, but it's only matching one dot

^([\w-]+[.-]?[']?[\w-]+)@([\w.-]+)$

How could I change the pattern to allow for up to two dots?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

^([\w\-]+\.?){0,2}[\w\-]+@[\w.\-]+$

The trick is to write "You can have a non-dotted characters before the @" ([\w\-]+@), but before that, you can have 0 to 2 times a dot-ended sequence: ([\w\-]+\.?){0,2}

I suggest you to escape your -, as in some circumstances it is a special instruction.

If you want to save the group capture you suggested (Elvis operator ?: prevents utility groups to be captured):

^((?:[\w\-]*\.?){0,2}[\w\-]+)@([\w.-]+)$
about 4 years ago · Juan Pablo Isaza Report
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!