33 public function validate($string, $config, $context)
35 $length = strlen($string);
45 if ($length > 1 && $string[0] ===
'[' && $string[$length - 1] ===
']') {
47 $ip = substr($string, 1, $length - 2);
48 $valid = $this->ipv6->validate($ip, $config, $context);
56 $ipv4 = $this->ipv4->validate($string, $config, $context);
57 if (
$ipv4 !==
false) {
77 $underscore = $config->get(
'Core.AllowHostnameUnderscore') ?
'_' :
'';
82 $and =
"[a-z0-9-$underscore]";
84 $domainlabel =
"$an($and*$an)?";
86 $toplabel =
"$a($and*$an)?";
88 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
96 if (function_exists(
'idn_to_ascii')) {
97 return idn_to_ascii($string);
101 } elseif ($config->get(
'Core.EnableIDNA')) {
103 $idna =
new Net_IDNA2(array(
'encoding' =>
'utf8',
'overlong' =>
false,
'strict' =>
true));
105 $parts = explode(
'.', $string);
107 $new_parts = array();
108 foreach ($parts as $part) {
110 for ($i = 0, $c = strlen($part); $i < $c; $i++) {
111 if (ord($part[$i]) > 0x7a) {
117 $new_parts[] = $part;
119 $new_parts[] = $idna->encode($part);
122 $string = implode(
'.', $new_parts);
123 if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
Base class for all validating attribute definitions.
Validates an IPv6 address.
Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
validate($string, $config, $context)
Validates an IPv4 address.