Javascript regex to match fully qualified domain name, without protocol, optional subdomain -
i haven't been able find 1 , i'm trying isn't quite working out me.
i want match domains that:
- don't contain protocol (http, https, ftp)
- optionally include subdomain
- don't start hyphen can contain hyphen
example domains match:
- domain.com
- example.domain.com
- example.domain-hyphen.com
- www.domain.com
- example.museum
example domains not match:
- http://example.com
- subdomain.-example.com
- example.com/parameter
- example.com?anything
- www.subdomain.domain.com
what i've got:
/^(?!:\/\/)(^[a-za-z0-9])?.[a-za-z0-9-]+\.[a-za-z]{2,6}?$/i
it's not matching protocols, allowing hyphen inside domain, not allowing trailing characters after tld, , allowing subdomain (but 1 character).
i still need allow subdomains of length, not allow www.subdomain.domain.com , not allow leading hyphen.
try
/^(?!:\/\/)([a-za-z0-9]+\.)?[a-za-z0-9][a-za-z0-9-]+\.[a-za-z]{2,6}?$/i
Comments
Post a Comment