Adds 'ip' to validator

main
Yasen Pramatarov 2025-02-24 14:47:23 +02:00
parent 2fc6940c11
commit d9bee210d4
1 changed files with 8 additions and 0 deletions

View File

@ -74,6 +74,14 @@ class Validator {
$this->addError($field, "Does not match $parameter field");
}
break;
case 'ip':
if (!empty($value)) {
// Support both IPv4 and IPv6
if (!filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) {
$this->addError($field, "Invalid IP address format");
}
}
break;
}
}