Class kartik\validators\PhoneValidator
Inheritance | kartik\validators\PhoneValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Uses Traits | kartik\base\TranslationTrait, kartik\validators\ValidatorTrait |
PhoneValidator validates phone numbers for given country and formats. The country codes and attributes value should be ISO 3166-1 alpha-2 codes.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$applyFormat | boolean | Whether to apply the parsed phone format and update the attribute | kartik\validators\PhoneValidator |
$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 |
$countryAttribute | string | The model attribute name that stores the country code value. | kartik\validators\PhoneValidator |
$countryRequired | boolean | Whether country code is mandatory for parsing the phone number | kartik\validators\PhoneValidator |
$countryRequiredMessage | string | The message to show if country value is empty and $countryRequired is true . |
kartik\validators\PhoneValidator |
$countryValue | string | The value for country code. | kartik\validators\PhoneValidator |
$enableClientValidation | boolean | Whether to enable client-side validation for this validator. | yii\validators\Validator |
$except | array|string | Scenarios that the validator should not be applied to. | yii\validators\Validator |
$format | string | The format to use when applying the format | kartik\validators\PhoneValidator |
$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 |
$message | string | The message to show if an invalid phone number is parsed. | kartik\validators\PhoneValidator |
$on | array|string | Scenarios that the validator can be applied to. | yii\validators\Validator |
$parseExceptionMessage | string | The message to show when a NumberParseException is thrown during phone number parsing. | kartik\validators\PhoneValidator |
$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
Property | Type | Description | Defined By |
---|---|---|---|
$_msgCat | string | Translation message file category name for i18n. | kartik\base\TranslationTrait |
Public Methods
Method | Description | Defined 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. | yii\validators\Validator |
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\Validator |
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\PhoneValidator |
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\PhoneValidator |
validateAttributes() | Validates the specified object. | yii\validators\Validator |
Protected Methods
Method | Description | Defined By |
---|---|---|
formatMessage() | Formats a mesage using the I18N, or simple strtr if \Yii::$app is not available. |
yii\validators\Validator |
initSettings() | Initializes the validator settings | kartik\validators\PhoneValidator |
setMsg() | Sets message property | kartik\validators\ValidatorTrait |
validateValue() | Validates a value. | yii\validators\Validator |
Property Details
Whether to apply the parsed phone format and update the attribute
The model attribute name that stores the country code value.
Whether country code is mandatory for parsing the phone number
The message to show if country value is empty and $countryRequired is true
.
The value for country code. This will override any value set in $countryAttribute. This is the ISO 3166-1 two letter country code. If the number is passed in an international format (e.g. +44 117 496 0123), then the region code is not needed, and can be null. Failing that, the library will use this value to work out the phone number based on rules loaded for that region.
The format to use when applying the format
See also [[PhoneNumberFormat]].
The message to show if an invalid phone number is parsed.
The message to show when a NumberParseException is thrown during phone number parsing.
Method Details
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 |
---|
Initializes the validator settings
protected void initSettings ( ) | ||
throws | ReflectionException |
---|
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. |