-3

Can someone please tell regular expression for this:

anytext.com
anytext.org
anytext.net
anytext.mil
anytext.gov

The requirement is any text given except these domain names (org, net, com, gov, mit) should be invalid.

Cuurently I am giving this regular expression which is not working:

/^[\w-\.]+.(?com)(?org)(?mil)(?net)(?edu)(?gov)?$/
Tushar
  • 82,599
  • 19
  • 151
  • 169
user3766619
  • 33
  • 1
  • 1
  • 5

1 Answers1

2

This should work for you:

var regexp = /^[A-Za-z0-9-\.]+\.(com|org|mil|net|gov)$/

console.log('anytext.com', regexp.test('anytext.com'))
dloeda
  • 1,496
  • 15
  • 23