JavaScript IPv4 Address Regex Validator
Validate a whole IPv4 address with four decimal numbers from 0 to 255. The pattern accepts a single zero and requires every other number to start with a nonzero digit.
Run the IPv4 examplesIPv4 regex for a form field
const ipv4Pattern = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/;
const isIPv4 = ipv4Pattern.test(value);For a single field, use the expression without flags. In the demo, m checks each line separately and g highlights every passing line.
The octet rules follow RFC 3986’s IPv4 syntax. A passing value confirms the address format. A service or network check takes additional information.
Test cases
- Pass
192.0.2.1Four decimal octets within range.
- Pass
0.0.0.0Zero is valid in each octet.
- Pass
255.255.255.255255 is the upper limit for each octet.
- Fail
256.0.0.1The first octet exceeds 255.
- Fail
192.168.001.1An octet has leading zeros.
- Fail
192.0.2.1/24A network prefix follows the address.
- Fail
192.0.2.1:443A port follows the address.
- Fail
2001:db8::1This value uses IPv6 notation.
Check the address type
Use the IPv4 and IPv6 address checker to identify private, loopback, or other special-use ranges. Paste the address in that tab to classify it locally.
Working with a hardware address? Use the MAC address regex guide.