mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Refactoring so regex has it's own variables
This commit is contained in:
@ -32,6 +32,17 @@ class EmailValidator extends Validator
|
|||||||
* @see allowName
|
* @see allowName
|
||||||
*/
|
*/
|
||||||
public $fullPattern = '/^[^@]*<[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?>$/';
|
public $fullPattern = '/^[^@]*<[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?>$/';
|
||||||
|
/**
|
||||||
|
* @var string the regular expression used to validate the part before the @ symbol, used if ASCII conversion fails to validate the address.
|
||||||
|
* @see http://www.regular-expressions.info/email.html
|
||||||
|
*/
|
||||||
|
public $patternASCII = '/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*$/';
|
||||||
|
/**
|
||||||
|
* @var string the regular expression used to validate email addresses with the name part before the @ symbol, used if ASCII conversion fails to validate the address.
|
||||||
|
* This property is used only when [[allowName]] is true.
|
||||||
|
* @see allowName
|
||||||
|
*/
|
||||||
|
public $fullPatternASCII = '/^[^@]*<[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*$/';
|
||||||
/**
|
/**
|
||||||
* @var bool whether to allow name in the email address (e.g. "John Smith <john.smith@example.com>"). Defaults to false.
|
* @var bool whether to allow name in the email address (e.g. "John Smith <john.smith@example.com>"). Defaults to false.
|
||||||
* @see fullPattern
|
* @see fullPattern
|
||||||
@ -186,11 +197,7 @@ class EmailValidator extends Validator
|
|||||||
{
|
{
|
||||||
$ascii = $this->idnToAscii($value);
|
$ascii = $this->idnToAscii($value);
|
||||||
if ($ascii === false) {
|
if ($ascii === false) {
|
||||||
$parts = explode('@', $this->pattern, 2);
|
if (preg_match($this->patternASCII, $value) || ($this->allowName && preg_match($this->fullPatternASCII, $value))) {
|
||||||
$pattern = $parts[0] . "$/";
|
|
||||||
$fullPatternParts = explode('@', $this->fullPattern);
|
|
||||||
$fullPattern = $fullPatternParts[0] . '@' . $fullPatternParts[1] ."$/";
|
|
||||||
if (preg_match($pattern, $value) || ($this->allowName && preg_match($fullPattern, $value))) {
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user