-1

I do have this regex that validates email addresses: ^\w+(\.\w+)*@(\w+\.)+\w{2,4}$

What I need is to append this current regex that will invalidate email addresses starting with none@ OR na@

How to? Thanks!

kkshinichi
  • 63
  • 1
  • 2
  • 10
  • 1
    Note that your regex does not validate all valid email addresses, and rejects many valid addressses. There's more information in the answers to [How to validate an email address using a regular expression?](https://stackoverflow.com/a/201378/43452) – Stobor Jul 23 '18 at 04:13
  • You may need to use grouping on the local part (the part before @) – Ṃųỻịgǻňạcểơửṩ Jul 23 '18 at 04:21

1 Answers1

2

Add negative lookahead to the beginning of the pattern:

^(?!none@|na@)\w+(\.\w+)*@(\w+\.)+\w{2,4}$

https://regex101.com/r/vf4WqT/1

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • can u please explain a little what is +\w{2,4} accounting for at the end – Inder Jul 23 '18 at 04:16
  • 2
    That was in the original pattern, so I'm assuming that's already matching what OP is looking for - a word character after a dot, repeated 2 to 4 times. For example, `bob@bob.com` (repeat 3x) is matched, but `bob@bob.c` (repeat 1x) wouldn't be, nor would `bob@bob.comom` (repeat 5x) – CertainPerformance Jul 23 '18 at 04:19
  • 1
    @Inder It's a bad `tld` validation. Would return false for `mobile` and other new TLDs. (I also dont think a TLD can have an underscore so `[a-z\d]` would be more accurate) – user3783243 Jul 23 '18 at 04:50