JavaScript-compatible regex reference

IPv4 Address Regex Pattern & Tester

Validate dotted-decimal IPv4 addresses with four octets constrained to the numeric range 0–255. This pattern is stricter than the common \d{1,3} shortcut, which also accepts impossible values such as 999.999.999.999.

Pattern

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

Flags: none

Live test vectors

Test the IPv4 address regex

Enter one value per line. Each line is tested against the whole-string pattern using the browser JavaScript RegExp engine.

PASS192.168.1.1
PASS10.0.0.1
PASS255.255.255.255
PASS0.0.0.0
FAIL256.1.1.1
FAIL192.168.1
FAIL999.999.999.999
FAIL01.2.3.4

Quick answer

A useful IPv4 validation regex must constrain each octet to 0–255, not merely one to three digits. This version also avoids leading-zero forms such as 01 in order to keep the accepted representation unambiguous.

Common use cases

  • Network configuration forms
  • Log and telemetry validation
  • Allowlist and blocklist input checks

Pitfalls and limitations

  • !\d{1,3} does not enforce the 0–255 range.
  • !Anchors are required when validating the entire field rather than searching inside a larger string.
  • !Some systems accept historical leading-zero forms; this pattern intentionally does not.

Known-valid examples

192.168.1.110.0.0.1255.255.255.2550.0.0.0

Known-invalid examples

256.1.1.1192.168.1999.999.999.99901.2.3.4

Continue testing and debugging

Frequently asked questions

Why not use \d{1,3} for each IPv4 octet?

Because it accepts values greater than 255. Range-aware alternatives are needed when the goal is validation rather than loose extraction.

Does this pattern accept leading zeros?

No. It accepts 0 but rejects forms such as 01 or 001 to avoid ambiguous textual representations.

Can this regex validate whether an IP is publicly routable?

No. It checks IPv4 syntax and numeric octet ranges only. Private, loopback, multicast, documentation, and other reserved ranges require separate semantic checks.