TLD & IP Regex

I needed to validate both a domain name and IP addresses in one regular expression (or: regex) and put this together:

(^((\w|\-|\d)+\.)+\w{2,20}$)|(^(\d{1,3}\.){3}\d{1,3}$)

It’ll match a single line to validate an IP or domain name, including any of the new TLDs at the time of writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/mcgraneu/public_html/wp-includes/functions.php on line 4344