1: <?php
2:
3: /**
4: * Pry Framework
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: *
11: */
12:
13: namespace Pry\Form\Element;
14:
15: use Pry\Form\Error;
16:
17: /**
18: * Element IP. Permet de valider une adresse IP dans un champs text
19: *
20: * @category Pry
21: * @package Form
22: * @subpackage Form_Element
23: * @version 1.0.0
24: * @author Olivier ROGER <oroger.fr>
25: *
26: */
27: class Ip extends Text
28: {
29:
30: /**
31: * Constructeur. Défini la taille mini et maxi de l'ip
32: *
33: * @param string $nom
34: * @param Form_Form $form
35: */
36: public function __construct($nom, $form)
37: {
38: parent::__construct($nom, $form);
39: $this->maxlength(15);
40: $this->minLength(7);
41: $this->showMask = true;
42: }
43:
44: /**
45: * Validation de l'adresse IP
46: *
47: * @param string $value
48: * @access public
49: * @return boolean
50: */
51: public function isValid($value)
52: {
53: if (parent::isValid($value))
54: {
55: if (\Pry\Util\Strings::isIp($value) || (!$this->required && $value == ''))
56: return true;
57: else
58: $this->errorMsg = Error::NOTIP;
59: }
60: return false;
61: }
62:
63: }
64:
65: ?>