-1

In Javascript I'm trying exclude a specific mail domain and all its subdomains using regex. If the domain I want to exclude is spammail.com. I need to exclude all the following

name@spammail.com
name@xx.spammail.com
name@xxx.spammail.com
...
Lalas M
  • 1,116
  • 1
  • 12
  • 29

1 Answers1

0

Try like this:

let checkValid = (mail) => !/([^\@]*\@)(([^\.]*\.{1})*)(spammail\.com)/.test(mail);

console.log(checkValid("name@spammail.com")) //false
console.log(checkValid("name@xx.spammail.com")) //false
console.log(checkValid("name@xxx.spammail.com")) //false
console.log(checkValid("name@notspammail.com")) //true
console.log(checkValid("name@xxxspammail.com")) //true
sbgib
  • 5,580
  • 3
  • 19
  • 26
  • Thanks .. but infact this accepts the spammail. What i was looking not to accept the spammail and its subdomains – Lalas M Nov 17 '20 at 09:08
  • 1
    It identifies the spam mail. You can then decide what you want to do with it :) – sbgib Nov 17 '20 at 09:10
  • @LalasM I've updated this answer to show how you can test an email address and receive true (valid) or false (not valid). – sbgib Nov 17 '20 at 09:18