validation
IPv4 Address Regex Pattern
Strictly validates an IPv4 address in dotted-quad form. Each octet is a number from 0-255 (not just 0-999). Rejects octets with too many digits or values above 255.
/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/ What each part matches
(25[0-5]|2[0-4]\d|[01]?\d\d?) — one octet: 250-255 OR 200-249 OR 0-199\. — literal dot{3} — three of the above 'octet + dot' groups(25[0-5]|...)$ — final octet, no trailing dot✓ These match
- 192.168.1.1
- 8.8.8.8
- 255.255.255.0
✗ These don't
- 256.1.1.1
- 192.168.1
- 192.168.001.1
- not.an.ip.address
Use in your code
JavaScript
const re = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
re.test(input); // → true or false Python
import re
re.fullmatch(r"^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$", input) PHP (PCRE)
preg_match('/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/', $input); Go
re := regexp.MustCompile(`^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$`)
re.MatchString(input) FAQ
Does this ipv4 address regex work in JavaScript?
Yes. Every pattern in the Utilko regex library is tested to work in JavaScript RegExp, PCRE (PHP, Nginx), and Python `re`. Where flavor matters (lookbehind, named groups), the pattern page flags it.
How do I use this pattern?
Copy the pattern from the code block above. In JavaScript:
new RegExp('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$') or literal /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/. Or click "Try in regex tester" to open it pre-loaded in Utilko's browser-based regex tester.Should I use this for security-critical validation?
Client-side regex is fine for UX (immediate feedback on a form). For anything security-critical — payments, auth, data integrity — always re-validate server-side using the same pattern PLUS domain-specific checks (Luhn checksum for cards, actual email delivery test, DNS resolution for domains).