ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
IPv4.php
Go to the documentation of this file.
1<?php
2
8{
9
14 protected $ip4;
15
22 public function validate($aIP, $config, $context)
23 {
24 if (!$this->ip4) {
25 $this->_loadRegex();
26 }
27
28 if (preg_match('#^' . $this->ip4 . '$#s', $aIP)) {
29 return $aIP;
30 }
31 return false;
32 }
33
38 protected function _loadRegex()
39 {
40 $oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
41 $this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})";
42 }
43}
44
45// vim: et sw=4 sts=4
Validates an IPv4 address.
Definition: IPv4.php:8
validate($aIP, $config, $context)
Definition: IPv4.php:22
$ip4
IPv4 regex, protected so that IPv6 can reuse it.
Definition: IPv4.php:14
_loadRegex()
Lazy load function to prevent regex from being stuffed in cache.
Definition: IPv4.php:38
Base class for all validating attribute definitions.
Definition: AttrDef.php:14