-4

I need a special regex for javascript to verify hostname is a subdomain, not a TLD. For example:

reject   domain.uk
accept   sub.domain.uk
reject   domain.ac.uk
accept   sub.domain.ac.uk
HA Luca
  • 1
  • 1
  • You need to be more precise. This is a complicated matter. See https://uasg.tech/ and https://publicsuffix.org/ but learn about its limitations first. – Patrick Mevzek May 15 '18 at 14:50

1 Answers1

0

Probably you need a blaklist and whitelist rather than a regex to handle this situation.

const blackList = ['http://', 'https://'];

const whiteList = ['www.domainname.uk', 'www.domainname.ac.uk']

if (blackList.indexOf(domain) < 0 && whiteList.indexOf(domain) >=0)
    console.log('Domain is good');
Charlie
  • 22,886
  • 11
  • 59
  • 90