laminas/laminas-validator
Laminas Validator provides flexible, reusable validation rules for PHP applications. Includes built-in validators, input filtering/validation chains, and tools for validating common data types like emails, URLs, numbers, strings, and more.
Laminas\Validator\HostWithPublicIPv4Address allows you to validate that an IP address is not a reserved address such as 127.0.0.1, or that a hostname does not point to a known, reserved address.
This validator has no options
$validator = new Laminas\Validator\HostWithPublicIPv4Address();
if ($validator->isValid('example.com')) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
$validator = new Laminas\Validator\HostWithPublicIPv4Address();
if ($validator->isValid('192.168.0.1')) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
When validating a hostname as opposed to an IP address, if that hostname resolves to multiple IPv4 addresses and any of those addresses are private or reserved, then the validator will deem the hostname invalid.
How can I help you explore Laravel packages today?