-8

I have this current regex expression to validate emails:

^([0-9a-zA-Z]([-.\\w\\+]*[0-9a-zA-Z\\+])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$

I want this to include "_" and "." to validate emails like these:

These are the valid emails that should pass/im validating: email@example.com

firstname.lastname@example.com

email@subdomain.example.com

firstname+lastname@example.com

Email@example.com

Email+book.28.feb@example.com

1234567890@example.com

email@example-one.com

_______@example.com

email@example.name

email@example.museum

email@example.co.jp

firstname-lastname@example.com

I've tried adding [0-9a-zA-Z_] an underline here but doesn't seem to work

1 Answers1

-1

This should work:

[\w.]+@\w+\.\w+
RifloSnake
  • 327
  • 1
  • 8
  • Where do I add this, could you give me the full line with this included, thanks alot – Afan Ajdari Mar 06 '23 at 15:03
  • This is the whole regex... – RifloSnake Mar 06 '23 at 15:11
  • Does not seem to work, this is what I have: ``const emailValidationRegex = "[\w.]+@\w+\.\w+";`` – Afan Ajdari Mar 06 '23 at 15:14
  • I don't have information about what you are doing with that, I just showed you regex that works, you can check it here https://regex101.com/r/AMdvA9/1 – RifloSnake Mar 06 '23 at 15:18
  • Well, I have a list of emails that should be valid, they include uppercase, underscore, plus symbol and dots, this is it (I will post these in the original post above aswell): ``email@example.com`` ``firstname.lastname@example.com`` ``email@subdomain.example.com`` ``firstname+lastname@example.com`` ``Email@example.com`` ``Email+book.28.feb@example.com`` ``1234567890@example.com`` ``email@example-one.com`` ``_______@example.com`` ``email@example.name`` ``email@example.museum`` ``email@example.co.jp`` ``firstname-lastname@example.com`` – Afan Ajdari Mar 06 '23 at 15:20
  • Sorry man I cant help you, you are not being clear at all, there are examples of + also inside the email, you didn't mention it. But you can add a + inside the square brackets inside my regex and it will work. Otherwise I don't know what to say. – RifloSnake Mar 06 '23 at 15:27