PHP FILTER_VALIDATE_IP Filter
Complete PHP Filter Reference Manual
Definition and Usage
The FILTER_VALIDATE_IP filter validates a value as an IP address.
- Name: "validate_ip"
- ID-number: 275
Possible flags:
- FILTER_FLAG_IPV4 - Requires the value to be a valid IPv4 IP (such as 255.255.255.255).
- FILTER_FLAG_IPV6 - Requires the value to be a valid IPv6 IP (such as 2001:0db8:85a3:08d3:1319:8a2e:0370:7334).
- FILTER_FLAG_NO_PRIV_RANGE - Requires the value not to be within the RFC-specified private range IPs (such as 192.168.0.1).
- FILTER_FLAG_NO_RES_RANGE - Requires the value not to be within the reserved IP ranges. This flag accepts both IPV4 and IPV6 values.
Example 1
The output of the code is shown below:
IP is valid
Example 2
The output of the code is shown below:
IP is valid
Complete PHP Filter Reference Manual