Skip to content

Commit

Permalink
Added EmailLocalPartValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 13, 2015
1 parent 23e4abe commit c8e2a77
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions src/validators/EmailLocalPartValidator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
<?php

/**
* Created by PhpStorm.
* User: silverfire
* Date: 13.11.15
* Time: 16:12
*/
* @link http://hiqdev.com/hipanel-module-hosting
* @license http://hiqdev.com/hipanel-module-hosting/license
* @copyright Copyright (c) 2015 HiQDev
*/

namespace hipanel\modules\hosting\validators;
use yii\validators\RegularExpressionValidator;

/**
* Class EmailLocalPart is used to validate Email local parts
*
* @package hipanel\modules\hosting\validators
*/
class EmailLocalPartValidator extends RegularExpressionValidator
{
/**
* @var string default validation pattern for the local part
*/
public $defaultPattern = '/^[0-9a-z_+-]([0-9a-z\._+-]+)?$/i';

/**
* @var string the same as [[defaultPattern]], but allows `*` character.
* Used when [[allowWildCard]] is true.
*/
public $defaultWildPattern = '/^(\*|([0-9a-z_+-]([0-9a-z\._+-]+)?))$/i';

/**
* @var bool Whether to allow `*` char instead of local part. Defaults to false.
*/
public $allowWildCard = false;

/**
* @inheritdoc
*/
public function init () {
$this->message = \Yii::t('app', '{attribute} is not a valid local part of email');

if ($this->pattern === null) {
$this->pattern = $this->allowWildCard ? $this->defaultWildPattern : $this->defaultPattern;
}
}
}

0 comments on commit c8e2a77

Please sign in to comment.