Class kartik\validators\EmailValidator

Inheritancekartik\validators\EmailValidator » yii\validators\EmailValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Uses Traitskartik\base\TranslationTrait, kartik\validators\ValidatorTrait

EmailValidator validates that the attribute value contains a list of valid emails separated by a delimiter.

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
$attributeNames array Attribute names. yii\validators\Validator
$attributes array|string Attributes to be validated by this validator. yii\validators\Validator
$behaviors yii\base\Behavior[] List of behaviors attached to this component. yii\base\Component
$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
$delimiter string The delimiter to separate multiple emails (applicable only when $multiple is true) kartik\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
$enableLocalIDN boolean Whether $enableIDN should apply to the local part of the email (left side of the @). 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
$fullPatternASCII 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. yii\validators\EmailValidator
$i18n array The the internalization configuration for this widget. kartik\base\TranslationTrait
$isEmpty callable|null A PHP callable that replaces the default implementation of isEmpty(). yii\validators\Validator
$max integer Maximum number of emails required (applicable only when $multiple is true). kartik\validators\EmailValidator
$maxThresholdMessage string The message when the number of emails are above the $max threshold kartik\validators\EmailValidator
$message string|null The user-defined error message. kartik\validators\EmailValidator
$min integer Minimum number of emails required (applicable only when $multiple is true). kartik\validators\EmailValidator
$minThresholdMessage string The message when the number of emails are below the $min threshold kartik\validators\EmailValidator
$multiple boolean Whether multiple email addresses are supported (separated by the $delimiter) kartik\validators\EmailValidator
$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
$patternASCII string The regular expression used to validate the part before the @ symbol, used if ASCII conversion fails to validate the address. 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
$validationAttributes array List of attribute names. yii\validators\Validator
$when callable|null A PHP callable whose return value determines whether this validator should be applied. yii\validators\Validator
$whenClient string|null A JavaScript function name whose return value determines whether this validator should be applied on the client-side. yii\validators\Validator

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_msgCat string Translation message file category name for i18n. kartik\base\TranslationTrait

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() Returns the JavaScript needed for performing client-side validation. kartik\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() Returns the client-side validation options. 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() Initializes the object. kartik\validators\EmailValidator
initI18N() Yii i18n messages configuration for generating translations kartik\base\TranslationTrait
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. kartik\validators\EmailValidator
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
initSettings() Initializes settings kartik\validators\EmailValidator
isDNSValid() yii\validators\EmailValidator
setMsg() Sets message property kartik\validators\ValidatorTrait
validateValue() Validates a value. yii\validators\EmailValidator

Property Details

$delimiter public property

The delimiter to separate multiple emails (applicable only when $multiple is true)

public string $delimiter ','
$max public property

Maximum number of emails required (applicable only when $multiple is true). Setting this to 0 or NULL will mean no maximum limit.

public integer $max 0
$maxThresholdMessage public property

The message when the number of emails are above the $max threshold

$message public property

The user-defined error message. It may contain the following placeholders which will be replaced accordingly by the validator:

  • {attribute}: the label of the attribute being validated
  • {value}: the value of the attribute being validated

Note that some validators may introduce other properties for error messages used when specific validation conditions are not met. Please refer to individual class API documentation for details about these properties. By convention, this property represents the primary error message used when the most important validation condition is not met.

public string|null $message null
$min public property

Minimum number of emails required (applicable only when $multiple is true). Setting this to 0 or NULL will mean no minimum limit.

public integer $min 0
$minThresholdMessage public property

The message when the number of emails are below the $min threshold

$multiple public property

Whether multiple email addresses are supported (separated by the $delimiter)

public boolean $multiple true

Method Details

clientValidateAttribute() public method

Returns the JavaScript needed for performing client-side validation.

Calls getClientOptions() to generate options array for client-side validation.

You may override this method to return the JavaScript validation code if the validator can support client-side validation.

The following JavaScript variables are predefined and can be used in the validation code:

  • attribute: an object describing the the attribute being validated.
  • value: the value being validated.
  • messages: an array used to hold the validation error messages for the attribute.
  • deferred: an array used to hold deferred objects for asynchronous validation
  • $form: a jQuery object containing the form element

The attribute object contains the following properties:

  • id: a unique ID identifying the attribute (e.g. "loginform-username") in the form
  • name: attribute name or expression (e.g. "[0]content" for tabular input)
  • container: the jQuery selector of the container of the input field
  • input: the jQuery selector of the input field under the context of the form
  • error: the jQuery selector of the error tag under the context of the container
  • status: status of the input field, 0: empty, not entered before, 1: validated, 2: pending validation, 3: validating
public string|null clientValidateAttribute ( $model, $attribute, $view )
$model yii\base\Model

The data model being validated

$attribute string

The name of the attribute to be validated.

$view yii\web\View

The view object that is going to be used to render views or view files containing a model form with this validator applied.

return string|null

The client-side validation script. Null if the validator does not support client-side validation.

init() public method

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )
throws ReflectionException
throws yii\base\InvalidConfigException
initSettings() protected method

Initializes settings

protected void initSettings ( $isMsgSet false )
$isMsgSet boolean

Whether $message property is set

throws ReflectionException
validateAttribute() public method

Validates a single attribute.

Child classes must implement this method to provide the actual validation logic.

public void validateAttribute ( $model, $attribute )
$model yii\base\Model

The data model to be validated

$attribute string

The name of the attribute to be validated.

throws yii\base\NotSupportedException