Dev Hub Solutions

Product studio

Get in touch

IPv4 address regex

Matches the shape of an IPv4 address: four decimal numbers (1–3 digits each) separated by dots. Anchored start to end.

The pattern

/^(?:\d{1,3}\.){3}\d{1,3}$/
Open in tester

Caveats

Doesn't validate that each octet is in range 0–255 — `999.999.999.999` matches this pattern. Strict IPv4 validation needs either a more elaborate regex or a one-liner using `Number(octet) <= 255` per group. For practical use, validate shape with the regex, then check ranges in code.

Test strings

A mix of values that should match and values that shouldn't — paste these into the tester to see them light up live.

  • 192.168.1.1
  • 10.0.0.255
  • 255.255.255.255
  • 999.999.999.999
  • 192.168.1
  • 192.168.1.1.5