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

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

Up ↑

%d bloggers like this: