Class CTypeValidator
CTypeValidator verifies if the attribute is of the type specified by CTypeValidator::$type
.
- integer A 32-bit signed integer data type.
- float A double-precision floating point number data type.
- string A string data type.
- array An array value.
- date A date data type.
- time A time data type.
- datetime A date and time data type.
For date type, the property CTypeValidator::$dateFormat
will be used to
determine how to parse the date string. If the given date value doesn't follow
the format, the attribute is considered as invalid.
Starting from version 1.1.7, we have a dedicated date validator CDateValidator
. Please consider using this validator to validate a date-typed
value.
CValidator::$message
property to define a custom error message, the
message may contain additional placeholders that will be replaced with the
actual content. In addition to the "{attribute}" placeholder, recognized by all
validators (see CValidator
), CTypeValidator allows for the following
placeholders to be specified:
- {type}: replaced with data type the attribute should be
CTypeValidator::$type
.
- CComponent
- CValidator
- CTypeValidator
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/CTypeValidator.php
protected
|
#
validateAttribute(
Validates the attribute of the object. If there is any error, the error message is added to the object. |
public
boolean
|
#
validateValue( mixed $value )
Validates a static value. Note that this method does not respect |
addError(),
applyTo(),
clientValidateAttribute(),
createValidator(),
isEmpty(),
validate()
|
public
string
|
$type | 'string' |
#
the data type that the attribute should be. Defaults to 'string'. Valid values include 'string', 'integer', 'float', 'array', 'date', 'time' and 'datetime'. |
public
string
|
$dateFormat | 'MM/dd/yyyy' |
#
the format pattern that the date value should follow. Defaults to
'MM/dd/yyyy'. Please see |
public
string
|
$timeFormat | 'hh:mm' |
#
the format pattern that the time value should follow. Defaults to 'hh:mm'.
Please see |
public
string
|
$datetimeFormat | 'MM/dd/yyyy hh:mm' |
#
the format pattern that the datetime value should follow. Defaults to
'MM/dd/yyyy hh:mm'. Please see |
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
boolean
|
$strict | false |
#
whether the actual PHP type of attribute value should be checked. Defaults to false, meaning that correctly formatted strings are accepted for integer and float validators. |
$attributes,
$builtInValidators,
$enableClientValidation,
$except,
$message,
$on,
$safe,
$skipOnError
|