* @var string the regular expression used to validate the attribute value.
* @var string the regular expression used to validate the attribute value.
@ -26,14 +24,12 @@ class CEmailValidator extends Validator
public $pattern = '/^[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 $pattern = '/^[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 email addresses with the name part.
* @var string the regular expression used to validate email addresses with the name part.
* This property is used only when {@link allowName} is true.
* This property is used only when [[allowName]] is true.
* @since 1.0.5
* @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 boolean whether to allow name in the email address (e.g. "Qiang Xue <qiang.xue@gmail.com>"). Defaults to false.
* @var boolean whether to allow name in the email address (e.g. "Qiang Xue <qiang.xue@gmail.com>"). Defaults to false.
* @since 1.0.5
* @see fullPattern
* @see fullPattern
*/
*/
public $allowName = false;
public $allowName = false;
@ -46,7 +42,6 @@ class CEmailValidator extends Validator
/**
/**
* @var boolean whether to check port 25 for the email address.
* @var boolean whether to check port 25 for the email address.
* Defaults to false.
* Defaults to false.
* @since 1.0.4
*/
*/
public $checkPort = false;
public $checkPort = false;
/**
/**
@ -58,16 +53,16 @@ class CEmailValidator extends Validator
/**
/**
* Validates the attribute of the object.
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param \yii\base\Model $object the object being validated
* @param string $attribute the attribute being validated
* @param string $attribute the attribute being validated
*/
*/
public function validateAttribute($object, $attribute)
public function validateAttribute($object, $attribute)
{
{
$value = $object->$attribute;
$value = $object->$attribute;
if ($this->allowEmpty && $this->isEmpty($value))
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
return;
if (!$this->validateValue($value))
}
{
if (!$this->validateValue($value)) {
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} is not a valid email address.');
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} is not a valid email address.');
$this->addError($object, $attribute, $message);
$this->addError($object, $attribute, $message);
}
}
@ -75,32 +70,32 @@ class CEmailValidator extends Validator
/**
/**
* Validates a static value to see if it is a valid email.
* Validates a static value to see if it is a valid email.
* Note that this method does not respect {@link allowEmpty} property.
* Note that this method does not respect [[allowEmpty]] property.
* This method is provided so that you can call it directly without going through the model validation rule mechanism.
* This method is provided so that you can call it directly without going through the model validation rule mechanism.
* @param mixed $value the value to be validated
* @param mixed $value the value to be validated
* @return boolean whether the value is a valid email
* @return boolean whether the value is a valid email
* @since 1.1.1
*/
*/
public function validateValue($value)
public function validateValue($value)
{
{
// make sure string length is limited to avoid DOS attacks
// make sure string length is limited to avoid DOS attacks