-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
  • 85,780
  • 21
  • 159
  • 179
user3766619
  • 63
  • 1
  • 2
  • 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,516
  • 15
  • 23