Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if url has domain name and not an ip

Tags:

javascript

How can I check if an url is made with an ip address instead of a domain name?

For example:

http://www.yeouuuuu.com/bla
https://www.bbc.co.uk/something
http://yeou:[email protected]/
//return true;
http://172.10.10.100/test
//return false; because there is an IP.

ip4 regex:

ipv4 = RegExp('((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|
  [0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])');
like image 626
yeouuu Avatar asked Oct 24 '25 15:10

yeouuu


1 Answers

Why not just test of window.location.hostname has any letter?

window.location.hostname.match(/[a-z]/i)

If it has even one letter then it's not an IP address. No?

like image 146
IMTheNachoMan Avatar answered Oct 27 '25 04:10

IMTheNachoMan