Class CNumberValidator
CNumberValidator validates that the attribute value is a number.
In addition to theCValidator::$message
property for setting a custom error message,
CNumberValidator has a couple custom error messages you can set that correspond
to different validation scenarios. To specify a custom message when the numeric
value is too big, you may use the CNumberValidator::$tooBig
property. Similarly with CNumberValidator::$tooSmall
. The messages may contain additional placeholders that will be
replaced with the actual content. In addition to the "{attribute}" placeholder,
recognized by all validators (see CValidator
), CNumberValidator allows
for the following placeholders to be specified:
- {min}: when using
CNumberValidator::$tooSmall
, replaced with the lower limit of the numberCNumberValidator::$min
. - {max}: when using
CNumberValidator::$tooBig
, replaced with the upper limit of the numberCNumberValidator::$max
.
- CComponent
- CValidator
- CNumberValidator
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/validators/CNumberValidator.php
protected
|
#
validateAttribute(
Validates the attribute of the object. If there is any error, the error message is added to the object. |
public
string
|
#
clientValidateAttribute(
Returns the JavaScript needed for performing client-side validation. |
addError(),
applyTo(),
createValidator(),
isEmpty(),
validate()
|
public
boolean
|
$integerOnly | false |
#
whether the attribute value can only be an integer. Defaults to false. |
public
boolean
|
$allowEmpty | true |
#
whether the attribute value can be null or empty. Defaults to true, meaning that if the attribute is empty, it is considered valid. |
public
integer|float
|
$max |
|
#
upper limit of the number. Defaults to null, meaning no upper limit. |
public
integer|float
|
$min |
|
#
lower limit of the number. Defaults to null, meaning no lower limit. |
public
string
|
$tooBig |
|
#
user-defined error message used when the value is too big. |
public
string
|
$tooSmall |
|
#
user-defined error message used when the value is too small. |
public
string
|
$integerPattern | '/^\s*[+-]?\d+\s*$/' |
#
the regular expression for matching integers. |
public
string
|
$numberPattern | '/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/' |
#
the regular expression for matching numbers. |
$attributes,
$builtInValidators,
$enableClientValidation,
$except,
$message,
$on,
$safe,
$skipOnError
|