IP address validation

Q

How to perform a validation on IP addresses using a regular expression? For example, "198.168.1.78" is an valid IP address.

✍: Guest

A

To perform a validation on IP addresses, try this regular expression:

^(([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5]).){3}([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])$

Click the button to test this regular expression here online:

2013-01-27, 2185👍, 0💬