-1

I want to validate an email field using regex in such a way that my email has to has @moore in it. like a@moore.af, b@moore.sg, and so on. how can I write its pattern? I am using typescript and angular reactive form.

Your help is much appreciated.

Talib Daryabi
  • 733
  • 1
  • 6
  • 28

1 Answers1

1

You can try to use ([\w-\.]+@moore\.[\w+]{1,5}) to match an email address, as I left a 1-5 characters' space for the domain name.

In JavaScript flavour: const regex = /([\w-\.]+@moore\.[\w+]{1,5})/gm; then you can use regex.test(str) to validate the email field.

Edit:

As @Toto pointed out, This regex matches .....@moore.++++. Better regex would be:
([a-zA-Z0-9\.-]+@moore\.[a-zA-Z0-9\.]{1,5})

to only accept alphabet/number in the domain name.

Mark
  • 999
  • 1
  • 7
  • 15
  • This regex matches `.....@moore.++++`, not sure it is a valid email address. – Toto Jan 06 '21 at 11:29
  • Thanks for pointing out @Toto, I updated the answer with a better solution to reflect this. – Mark Jan 06 '21 at 12:48