54 return preg_match(
"/^[\/0-9 ()+*-]+$/", $nr);
65 return preg_match(
"/^[a-z0-9\.\-_]*$/i", $str);
76 return preg_match(
"/^[a-z0-9\.\-]*$/i", $str);
92 return preg_match(
"@^(https?)://[^\s/$.?#].[^\s]*$@i", $url);
107 return preg_match(
"/^[a-z0-9 _-]+$/i", $dn);
125 return preg_match(
"/^[a-z0-9_-]+$/", $uid);
127 return preg_match(
"/^[a-z0-9 _.-]+$/i", $uid);
138 return filter_var($ip, FILTER_VALIDATE_IP);
148 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
158 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
169 return preg_match(
'/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/', $mac);
183 for ($e = 0; $e <= 32; $e++) {
190 for ($a = 3; $a >= 0; $a--) {
193 $str = $i[0].
".".$i[1].
".".$i[2].
".".$i[3];
199 $res[
"0.0.0.0"] =
"0.0.0.0";
200 if (preg_match(
"/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
201 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
202 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
203 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)) {
204 $mask = preg_replace(
"/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
205 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
206 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.".
207 "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/",
"", $ip);
209 $mask = preg_replace(
"/^\//",
"", $mask);
210 if ((in_array(
"$mask", $res)) && preg_match(
"/^[0-9\.]/", $mask)) {
227 return preg_match(
"/^(([a-z0-9\-]{2,63})\.)*[a-z]{2,63}$/i", $str);
242 return preg_match(
"/^[0-9]+$/", $id);
256 if (!preg_match(
'/^[a-z0-9%\/_.+-]+$/i', $path)) {
260 return preg_match(
"/\/.+$/", $path);
272 return (($address ==
'')
273 || (filter_var($address, FILTER_VALIDATE_EMAIL) !== FALSE)
274 || (filter_var($address.
'.com', FILTER_VALIDATE_EMAIL) !== FALSE));
285 public static function is_department_name_reserved ($name)
289 foreach ($config->data[
'OBJECTS'] as $infos) {
290 if (isset($infos[
'ou']) && preg_match(
'/ou=([^,]+),$/', $infos[
'ou'], $m)) {
291 $reservedNames[] = $m[1];
295 return in_array_ics($name, array_unique($reservedNames));
308 public static function is_ip_range ($ip1, $ip2)
313 $ar1 = array_map(
'intval', explode(
'.', $ip1));
314 $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3];
316 $ar2 = array_map(
'intval', explode(
'.', $ip2));
317 $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3];
318 return ($var1 < $var2);
332 public static function is_in_network ($network, $netmask, $address)
334 $nw = array_map(
'intval', explode(
'.', $network));
335 $nm = array_map(
'intval', explode(
'.', $netmask));
336 $ad = array_map(
'intval', explode(
'.', $address));
341 for ($i = 0; $i < 4; $i++) {
342 $ni[$i] = 255 - $nm[$i];
343 $la[$i] = $nw[$i] | $ni[$i];
347 $first = $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3];
348 $curr = $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
349 $last = $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3];
351 return ($first < $curr && $last > $curr);
355 public static function is_in_ip_range ($from, $to, $address)
357 $from = array_map(
'intval', explode(
'.', $from));
358 $to = array_map(
'intval', explode(
'.', $to));
359 $ad = array_map(
'intval', explode(
'.', $address));
362 $from = $from[0] * (16777216) + $from[1] * (65536) + $from[2] * (256) + $from[3];
363 $to = $to[0] * (16777216) + $to[1] * (65536) + $to[2] * (256) + $to[3];
364 $ad = $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3];
366 return ($ad >= $from && $ad <= $to);
370 public static function is_orcid ($orcid)
373 $baseDigits = str_split(str_replace(
'-',
'', substr($orcid, 0, -1)));
375 foreach ($baseDigits as $baseDigit) {
376 $sum = ($sum + (int)$baseDigit) * 2;
378 $remainder = $sum % 11;
379 $result = (12 - $remainder) % 11;
380 $orcidCheckSum = (($result == 10) ?
"X" : (
string)$result);
382 return ($orcidCheckSum != substr($orcid, -1));
static is_ipv4($ip)
Test if the given string is an IPv4.
in_array_ics($value, array $items)
Check if a value exists in an array (case-insensitive)
static is_path($path)
Check if the given argument is a path.
static is_phone_nr($nr)
Test if the given string is a phone number.
static is_url($url)
Test if the given string is an URL.
static is_uid($uid)
Test if the given string is an uid.
static is_valid_hostname($str)
Test if the given string contains characters allowed in a hostname.
static is_dn($dn)
Test if the given string is a DN.
static is_ip($ip)
Test if the given string is an IP (v4 or v6)
static is_dns_name($str)
Test if the given string contains characters allowed in a DNS record name.
strict_uid_mode()
Check if strict naming rules are configured.
static is_ip_with_subnetmask($ip)
Checks if the given ip address doesn't match "is_ip" because there is also a sub net mask given...
static is_email($address)
Check if the given argument is an email.
static is_domain($str)
Simple is domain check.
This class provides various test functions.
static is_mac($mac)
Test if the given string is a mac address.
static is_ipv6($ip)
Test if the given string is an IPv6.
static is_id($id)
Check if the given argument is an id.