1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: namespace Jyxo\Input\Validator;
15:
16: /**
17: * Validates a IPv4 address.
18: *
19: * @category Jyxo
20: * @package Jyxo\Input
21: * @subpackage Validator
22: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
23: * @license https://github.com/jyxo/php/blob/master/license.txt
24: * @author Jaroslav HanslĂk
25: */
26: class IsIpV4 extends \Jyxo\Input\Validator\AbstractValidator
27: {
28: /**
29: * Validates a value.
30: *
31: * @param mixed $value Input value
32: * @return boolean
33: */
34: public function isValid($value)
35: {
36: $pattern8bit = '(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])';
37: $patternIpV4 = '(?:' . $pattern8bit . '(?:[.]' . $pattern8bit . '){3})';
38:
39: if (!preg_match('~^' . $patternIpV4 . '$~', (string) $value)) {
40: return false;
41: }
42:
43: return true;
44: }
45: }
46: