Build an IP address validation regex

Check whether text is a dotted-quad IPv4 address.

freeworks offlinenothing uploaded
ToolIP Address Regex
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

The pattern checks four dot-separated decimal octets with bounded values and anchors the complete input. It targets IPv4 text, not IPv6 or CIDR.

  • Dotted-quad notation is familiar in firewall and log tools.
  • Strict ranges avoid oversized octets.

Worked example

IPv4 address validation pattern
Get the regex pattern for validating IPv4 addresses
Input
											ipv4
										
Output
												IP Regex (ipv4):

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

IPv4 address (e.g., 192.168.1.1)
											

When to use this

Firewall forms, log filters, and allowlist editors check IPv4 text.

Edge cases

  • 999.1.1.1 has the wrong numeric range.
  • Leading-zero octets can be interpreted differently by legacy parsers.
  • ::1 needs an IPv6 grammar.

References