IP Address
Validate IPv4 and IPv6 addresses
IP Address
The ip rule checks that a value is a valid IPv4 or IPv6 address. ipv4 and ipv6 restrict the check to a single family.
What it checks
- IPv4: four octets of 0–255, e.g.
192.168.1.1 - IPv6: standard hexadecimal colon notation, e.g.
2001:db8::1
Config flag
The config flag ip: true accepts either family:
validationSchema: {
ip: { ip: true },
}With a custom message:
ip: { ip: "Enter a valid IP address" }V builder
import { V } from "formify-js";
V.ip() // IPv4 or IPv6
V.ipv4() // IPv4 only
V.ipv6() // IPv6 onlyEach accepts an optional message: V.ipv4("Enter a valid IPv4 address").
Default message
Please enter a valid IP address
Things to know
- Empty values pass unless
required: trueis also set. - There is no separate
ipv4/ipv6config flag — use theVbuilder when you need to restrict the family.