Browse Source

Merge branch 'feature_new_validators' into extended_classes

namespace
Alexander Demidov 11 years ago
parent
commit
f9de8ee3bc
  1. 7
      validator/EmailValidator.php
  2. 39
      validator/MbStrlenValidator.php
  3. 39
      validator/StrlenValidator.php

7
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(){}
}

39
validator/MbStrlenValidator.php

@ -0,0 +1,39 @@
<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @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;
}
}

39
validator/StrlenValidator.php

@ -0,0 +1,39 @@
<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @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;
}
}
Loading…
Cancel
Save