-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23e4abe
commit c8e2a77
Showing
1 changed file
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |