From 3b6ae397071d25dba682ce44385f22edef022e29 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Wed, 12 Dec 2012 13:11:54 +0400 Subject: [PATCH 1/2] Added new validators without tests --- validator/MbStrlenValidator.php | 39 +++++++++++++++++++++++++++++++++++++++ validator/StrlenValidator.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 validator/MbStrlenValidator.php create mode 100644 validator/StrlenValidator.php diff --git a/validator/MbStrlenValidator.php b/validator/MbStrlenValidator.php new file mode 100644 index 0000000..7f66555 --- /dev/null +++ b/validator/MbStrlenValidator.php @@ -0,0 +1,39 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage forms + * @since 17.05.12 + * @author Aleksander Demidov + * + */ + +class MbStrlenValidator extends Validator +{ + + const GREATHER_THAN = 'not_match'; + + protected $templates = array(self::GREATHER_THAN => 'String length greather than.'); + + protected $token; + + public function __construct($token) + { + $this->token = $token; + } + + public function isValid($value, $context = null) + { + $this->setValue($value); + if ($this->token === null) { + throw new InitializationException('Token not defined.'); + } + + if (mb_strlen($value) > $this->token) { + $this->error(); + return false; + } + return true; + } +} \ No newline at end of file diff --git a/validator/StrlenValidator.php b/validator/StrlenValidator.php new file mode 100644 index 0000000..a6ebcbc --- /dev/null +++ b/validator/StrlenValidator.php @@ -0,0 +1,39 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage forms + * @since 17.05.12 + * @author Aleksander Demidov + * + */ + +class StrlenValidator extends Validator +{ + + const GREATHER_THAN = 'not_match'; + + protected $templates = array(self::GREATHER_THAN => 'String length greather than.'); + + protected $token; + + public function __construct($token) + { + $this->token = $token; + } + + public function isValid($value, $context = null) + { + $this->setValue($value); + if ($this->token === null) { + throw new InitializationException('Token not defined.'); + } + + if (strlen($value) > $this->token) { + $this->error(); + return false; + } + return true; + } +} \ No newline at end of file From 625752ced700b6be22452d6d7815d433a789197c Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Wed, 31 Jul 2013 08:32:05 +0400 Subject: [PATCH 2/2] Modified EmailValidator add links to rfc specifications. --- validator/EmailValidator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/validator/EmailValidator.php b/validator/EmailValidator.php index 78c0731..7c7c565 100644 --- a/validator/EmailValidator.php +++ b/validator/EmailValidator.php @@ -9,7 +9,12 @@ class EmailValidator extends RegexValidator { - protected $regex = '/^([a-z0-9._-]{2,23})\@([a-z0-9-]{2,22}\.)+\w{2,5}$/i'; + /** + * @var string + * https://tools.ietf.org/html/rfc5322#section-3.4.1 + * https://tools.ietf.org/html/rfc5321#section-4.5.3 + */ + protected $regex = '/^([a-z0-9._-]{1,64})\@([a-z0-9-]{2,250}\.)+\w{2,5}$/i'; public function __construct(){} } \ No newline at end of file