Class yii\validators\NumberValidator
Inheritance | yii\validators\NumberValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/validators/NumberValidator.php |
NumberValidator validates that the attribute value is a number.
The format of the number must match the regular expression specified in $integerPattern or $numberPattern. Optionally, you may configure the $max and $min properties to ensure the number is within certain range.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$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 |
$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 |
$integerOnly | boolean | Whether the attribute value can only be an integer. | yii\validators\NumberValidator |
$integerPattern | string | The regular expression for matching integers. | yii\validators\NumberValidator |
$isEmpty | callable | A PHP callable that replaces the default implementation of isEmpty(). | yii\validators\Validator |
$max | integer|float | Upper limit of the number. | yii\validators\NumberValidator |
$message | string | The user-defined error message. | yii\validators\Validator |
$min | integer|float | Lower limit of the number. | yii\validators\NumberValidator |
$numberPattern | string | The regular expression for matching numbers. | yii\validators\NumberValidator |
$on | array|string | Scenarios that the validator can be applied to. | yii\validators\Validator |
$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 |
$tooBig | string | User-defined error message used when the value is bigger than $max. | yii\validators\NumberValidator |
$tooSmall | string | User-defined error message used when the value is smaller than $min. | yii\validators\NumberValidator |
$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
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() | {@inheritdoc} | yii\validators\NumberValidator |
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\NumberValidator |
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\NumberValidator |
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() | {@inheritdoc} | yii\validators\NumberValidator |
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 |
validateValue() | {@inheritdoc} | yii\validators\NumberValidator |
Property Details
Whether the attribute value can only be an integer. Defaults to false.
The regular expression for matching integers.
Upper limit of the number. Defaults to null, meaning no upper limit.
See also $tooBig for the customized message used when the number is too big.
Lower limit of the number. Defaults to null, meaning no lower limit.
See also $tooSmall for the customized message used when the number is too small.
The regular expression for matching numbers. It defaults to a pattern that matches floating numbers with optional exponential part (e.g. -1.23e-10).
User-defined error message used when the value is bigger than $max.
User-defined error message used when the value is smaller than $min.
Method Details
{@inheritdoc}
public void clientValidateAttribute ( $model, $attribute, $view ) | ||
$model | ||
$attribute | ||
$view |
{@inheritdoc}
public void getClientOptions ( $model, $attribute ) | ||
$model | ||
$attribute |
{@inheritdoc}
public void init ( ) |
{@inheritdoc}
public void validateAttribute ( $model, $attribute ) | ||
$model | ||
$attribute |
{@inheritdoc}
protected void validateValue ( $value ) | ||
$value |