laminas/laminas-validator
Validation component for PHP and Laminas applications. Provides a wide range of ready-to-use validators (strings, numbers, dates, files, and more), consistent error messages, and an extensible API to create custom validators and input filtering rules.
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?