Class yii\validators\EmailValidator

Inheritanceyii\validators\EmailValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/validators/EmailValidator.php

EmailValidator validates that the attribute value is a valid email address.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$allowName boolean Whether to allow name in the email address (e.g. "John Smith <john. yii\validators\EmailValidator
$attributes array|string Attributes to be validated by this validator. yii\validators\Validator
$builtInValidators array List of built-in validators (name => class or configuration) yii\validators\Validator
$checkDNS boolean Whether to check whether the email's domain exists and has either an A or MX record. yii\validators\EmailValidator
$enableClientValidation boolean Whether to enable client-side validation for this validator. yii\validators\Validator
$enableIDN boolean Whether validation process should take into account IDN (internationalized domain names). yii\validators\EmailValidator
$except array|string Scenarios that the validator should not be applied to. yii\validators\Validator
$fullPattern string The regular expression used to validate email addresses with the name part. yii\validators\EmailValidator
$isEmpty callable A PHP callable that replaces the default implementation of isEmpty(). yii\validators\Validator
$message string The user-defined error message. yii\validators\Validator
$on array|string Scenarios that the validator can be applied to. yii\validators\Validator
$pattern string The regular expression used to validate the attribute value. yii\validators\EmailValidator
$skipOnEmpty boolean Whether this validation rule should be skipped if the attribute value is null or an empty string. yii\validators\Validator
$skipOnError boolean Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules. yii\validators\Validator
$when callable A PHP callable whose return value determines whether this validator should be applied. yii\validators\Validator
$whenClient string A JavaScript function name whose return value determines whether this validator should be applied on the client-side. yii\validators\Validator

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addError() Adds an error about the specified attribute to the model object. yii\validators\Validator
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
clientValidateAttribute() {@inheritdoc} yii\validators\EmailValidator
createValidator() Creates a validator object. yii\validators\Validator
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getAttributeNames() Returns cleaned attribute names without the ! character at the beginning. yii\validators\Validator
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getClientOptions() {@inheritdoc} yii\validators\EmailValidator
getValidationAttributes() Returns a list of attributes this validator applies to. yii\validators\Validator
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() {@inheritdoc} yii\validators\EmailValidator
isActive() Returns a value indicating whether the validator is active for the given scenario and attribute. yii\validators\Validator
isEmpty() Checks if the given value is empty. yii\validators\Validator
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
trigger() Triggers an event. yii\base\Component
validate() Validates a given value. yii\validators\Validator
validateAttribute() Validates a single attribute. yii\validators\Validator
validateAttributes() Validates the specified object. yii\validators\Validator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
formatMessage() Formats a mesage using the I18N, or simple strtr if \Yii::$app is not available. yii\validators\Validator
isDNSValid() yii\validators\EmailValidator
validateValue() {@inheritdoc} yii\validators\EmailValidator

Property Details

$allowName public property

Whether to allow name in the email address (e.g. "John Smith john.smith@example.com"). Defaults to false.

See also $fullPattern.

public boolean $allowName false
$checkDNS public property

Whether to check whether the email's domain exists and has either an A or MX record. Be aware that this check can fail due to temporary DNS problems even if the email address is valid and an email would be deliverable. Defaults to false.

public boolean $checkDNS false
$enableIDN public property

Whether validation process should take into account IDN (internationalized domain names). Defaults to false meaning that validation of emails containing IDN will always fail. Note that in order to use IDN validation you have to install and enable intl PHP extension, otherwise an exception would be thrown.

public boolean $enableIDN false
$fullPattern public property

The regular expression used to validate email addresses with the name part. This property is used only when $allowName is true.

See also $allowName.

public string $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])?>$/'
$pattern public property

The regular expression used to validate the attribute value.

See also http://www.regular-expressions.info/email.html.

public string $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])?$/'

Method Details

clientValidateAttribute() public method

{@inheritdoc}

public void clientValidateAttribute ( $model, $attribute, $view )
$model
$attribute
$view
getClientOptions() public method

{@inheritdoc}

public void getClientOptions ( $model, $attribute )
$model
$attribute
init() public method

{@inheritdoc}

public void init ( )
isDNSValid() protected method
protected boolean isDNSValid ( $domain )
$domain string
return boolean

If DNS records for domain are valid

validateValue() protected method

{@inheritdoc}

protected void validateValue ( $value )
$value