I want to validate domain names using Regex, here is my regex so far:
/^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9])\.[a-zA-Z]{2,3})$/;
The above line would also allow multiple dashes
in the address, like this--is.com
which is obviously wrong, how this could be fixed?
I need the domain in the most simple way, like google.com
to be validated only
, no protocols, sub domain etc is allowed.
So these will be ok:
google.com
yahoo-new.com
newdomain.travel
And not OK:
http://google.com
www.yahoo.com
http://www.blah.com