splitforms.com

Free tool · runs in your browser

IP address regex tester

Test IPv4 and IPv6 patterns with strict 0-255 octets, :: compressed forms, IPv4-mapped addresses, CIDR suffixes and private ranges. Pick a preset, edit the regex, paste addresses one per line, then copy JavaScript or an HTML pattern snippet.

Four dotted octets 0-255. Leading zeros such as 01 or 010 fail, because some parsers read them as octal.

3 of 12 match

  • Match192.168.1.1
  • Match8.8.8.8
  • No match256.1.1.1
  • No match01.2.3.4
  • No match1.2.3
  • No match10.0.0.0/8
  • No match2001:db8::1
  • No match::1
  • No match::ffff:192.0.2.128
  • No match1:2:3:4:5:6:7:8:9
  • No match2001:db8:::1
  • Match172.20.10.5

HTML pattern is checked with the v flag in modern browsers. Regex is fine for form input, but server code should check again: in Node, use net.isIP(value) (returns 4, 6 or 0).

Why \d{1,3} is not enough for IPv4

The common shortcut ^(\d{1,3}\.){3}\d{1,3}$ accepts 999.999.999.999. The strict preset spells out each octet range (250-255, 200-249, 100-199, 0-99) and does not allow leading zeros, so 01.2.3.4 fails. Some parsers read a leading zero as octal, which turns 010.0.0.1 into a different address.

IPv4, IPv6 and CIDR patterns

Default preset: ^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$. Every preset below was checked against its examples with the plain, u and v flags.

PresetRegexMatch / no match examplesNotes
IPv4 (strict)^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$Match: 192.168.1.1, 0.0.0.0, 255.255.255.255, 8.8.8.8, 10.0.0.254
No match: 256.1.1.1, 01.2.3.4, 1.2.3, 1.2.3.4.5, 1.2.3.4/24, ::1, 1.2.3.4
Four dotted octets 0-255. Leading zeros such as 01 or 010 fail, because some parsers read them as octal.
IPv4 with CIDR^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\/(?:3[0-2]|[12]?\d))?$Match: 10.0.0.0/8, 192.168.0.0/16, 0.0.0.0/0, 1.2.3.4/32, 8.8.8.8
No match: 10.0.0.0/33, 1.2.3.4/, 1.2.3.4/024, 256.1.1.1/24, 1.2.3/24
Same strict IPv4 plus an optional /0-32 prefix length.
IPv6 (full, :: and IPv4-mapped)^(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|::(?:ffff(?::0{1,4})?:)?(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))$Match: 2001:0db8:85a3:0000:0000:8a2e:0370:7334, 2001:db8::1, ::1, ::, fe80::, ::ffff:192.0.2.128, 64:ff9b::192.0.2.33, 1:2:3:4:5:6:7:8
No match: 1:2:3:4:5:6:7:8:9, 2001:db8:::1, 1::2::3, 12345::1, 2001:db8::g1, ::ffff:256.1.1.1, 192.168.1.1
Covers the full 8-group form, every :: compressed form and IPv4-mapped addresses like ::ffff:192.0.2.128. Zone IDs (fe80::1%eth0) are not accepted.
IPv6 with CIDR^(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|::(?:ffff(?::0{1,4})?:)?(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))(?:\/(?:12[0-8]|1[01]\d|[1-9]?\d))?$Match: 2001:db8::/32, ::/0, fe80::/10, ::1/128, 2001:db8::1
No match: 2001:db8::/129, ::1/, 2001:db8::/032, 2001:db8:::1/64
Any IPv6 form above plus an optional /0-128 prefix length.
IPv4 or IPv6^(?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|(?:[0-9a-fA-F]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|::(?:ffff(?::0{1,4})?:)?(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))$Match: 192.168.1.1, 8.8.8.8, 2001:db8::1, ::1, ::ffff:10.0.0.1
No match: 256.1.1.1, 01.2.3.4, 1.2.3, 1:2:3:4:5:6:7:8:9, 2001:db8:::1, localhost
Accepts either family. Use it for a single “IP address” field; check the family on the server if you need one.
Private IPv4 (RFC 1918)^(?:10(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}|172\.(?:1[6-9]|2\d|3[01])(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){2}|192\.168(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){2})$Match: 10.0.0.1, 10.255.255.255, 172.16.0.1, 172.31.255.255, 192.168.1.1
No match: 172.15.0.1, 172.32.0.1, 192.169.1.1, 11.0.0.1, 8.8.8.8, 010.0.0.1
Only the private ranges 10.0.0.0/8, 172.16.0.0/12 (172.16-172.31) and 192.168.0.0/16.

HTML IP address input

ip.html

<label for="ip">Server IP address</label>
<input id="ip" name="ip" type="text" inputmode="decimal" pattern="(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)" title="IPv4 address, for example 192.168.1.1" maxlength="15" required>

Use the pattern attribute without ^ or $ (the browser anchors the whole value). Browsers compile it with the v flag, so a - inside a character class must be escaped. Pair it with required and a maxlength (15 for IPv4, 45 for IPv6).

Check again on the server

Regex is fine for form input, but server code should parse the address too. In Node, net.isIP() returns 4, 6 or 0 and handles every valid IPv6 form.

validate-ip.js

import { isIP } from "node:net";

const IPV4_RE = new RegExp("^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$", "u");
const value = input.trim();
const looksOk = IPV4_RE.test(value);   // quick form check
const family = isIP(value);           // 4, 6 or 0 (invalid): trust this one
validate-ip.php

$ip = trim($_POST['ip'] ?? '');
$ok = filter_var($ip, FILTER_VALIDATE_IP) !== false;
// IPv4 only: FILTER_VALIDATE_IP, FILTER_FLAG_IPV4
// Public only: add FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
validate-ip.py

import ipaddress

try:
    ip = ipaddress.ip_address(value.strip())
    ok, private = True, ip.is_private
except ValueError:
    ok, private = False, False

IP address regex FAQ

What is the regex for an IPv4 address?

Use ^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$. Each octet is limited to 0-255 and leading zeros such as 01.2.3.4 fail. A simpler \d{1,3} pattern wrongly accepts 999.1.1.1.

How do I match IPv6 with regex, including ::?

IPv6 needs an alternation: one branch for the full 8 groups, and one branch for each place the :: shorthand can appear, plus branches for IPv4-mapped forms like ::ffff:192.0.2.128. The IPv6 preset above covers all of them and rejects 2001:db8:::1 and 9-group addresses.

How do I allow a CIDR suffix like /24?

Add (?:\/(?:3[0-2]|[12]?\d))? after the IPv4 pattern for /0-32, or (?:\/(?:12[0-8]|1[01]\d|[1-9]?\d))? after the IPv6 pattern for /0-128. Leave the group out if the field must hold a single host address.

Which regex matches only private IP addresses?

The private IPv4 preset matches 10.0.0.0/8, 172.16.0.0/12 (172.16 to 172.31) and 192.168.0.0/16. On the server, Python’s ipaddress.ip_address(x).is_private and PHP’s FILTER_FLAG_NO_PRIV_RANGE do the same check without regex.

Is regex enough to validate an IP address on the server?

Regex is fine for form input, but server code should use a real parser: net.isIP() in Node, filter_var with FILTER_VALIDATE_IP in PHP, or the ipaddress module in Python. They handle every valid form and return the address family.

More free form tools

Form backend cost calculator

Enter monthly submissions and compare the cheapest listed plan across eight form backends.

Email deliverability checker

Enter a domain to check its SPF, DMARC and MX records and get a plain-English fix for each.

SPF record checker

Look up a domain's SPF record, see each mechanism explained and count DNS lookups against the 10-lookup limit.

DMARC record generator

Pick a policy and report address and copy a ready _dmarc TXT record.

DMARC checker

Look up a domain's DMARC record and see the policy and every tag explained.

DKIM record checker

Enter a domain and selector to check its DKIM key, with presets for common senders.

SPF record generator

Tick your email providers and copy one SPF TXT record with a lookup count.

Contact form spam checker

Paste form HTML to audit its honeypot, endpoint, CAPTCHA markers and spam resistance.

Honeypot field generator

Generate a hidden anti-spam input with your chosen name and hiding technique.

Form action URL tester

Check a form action URL for reachability, CORS headers, POST acceptance and backend.

Email obfuscator

Encode your email so spam scrapers can't read it but people can still click it.

Mailto link generator

Build a mailto: URL with recipients, CC, BCC, subject and a pre-filled body.

HMAC-SHA256 generator

Generate and verify webhook signatures for common providers in your browser.

URL encoder and decoder

Encode text, build an x-www-form-urlencoded body or parse a query string.

UTM builder

Build campaign URLs with UTM parameters, tag a CSV in bulk and check tagged links.

HTML to JSX converter

Paste HTML and get JSX or a working React/Next.js form component.

Image to Base64 converter

Convert images to Base64 data URLs in your browser and copy HTML and CSS snippets.

Base64 to image converter

Paste a Base64 data URI to preview and download the decoded image.

Base64 decode & encode

Decode Base64 to readable UTF-8 text or encode text to Base64, locally in your browser.

URL to Base64 converter

Fetch a direct image URL in your browser and get its Base64 data URL.

AI form generator

Describe your form in plain English and copy working HTML.

See all free tools