CTypeValidator
CTypeValidator verifies if the attribute is of the type specified by
type.
The following data types are supported:
- 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 (available since version 1.0.5).
- datetime A date and time data type (available since version 1.0.5).
For
date type, the property
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.
Public Properties
Hide inherited properties
| Property | Type | Description | Defined By |
| allowEmpty |
boolean |
whether the attribute value can be null or empty. |
CTypeValidator |
| attributes |
array |
list of attributes to be validated. |
CValidator |
| builtInValidators |
array |
list of built-in validators (name=>class) |
CValidator |
| dateFormat |
string |
the format pattern that the date value should follow. |
CTypeValidator |
| datetimeFormat |
string |
the format pattern that the datetime value should follow. |
CTypeValidator |
| message |
string |
the user-defined error message. |
CValidator |
| on |
array |
list of scenarios that the validator should be applied. |
CValidator |
| skipOnError |
boolean |
whether this validation rule should be skipped if when there is already a validation
error for the current attribute. |
CValidator |
| timeFormat |
string |
the format pattern that the time value should follow. |
CTypeValidator |
| type |
string |
the data type that the attribute should be. |
CTypeValidator |
Property Details
public boolean $allowEmpty;
whether the attribute value can be null or empty. Defaults to true,
meaning that if the attribute is empty, it is considered valid.
public string $dateFormat;
the format pattern that the date value should follow. Defaults to 'MM/dd/yyyy'.
Please see CDateTimeParser for details about how to specify a date format.
This property is effective only when type is 'date'.
public string $datetimeFormat;
the format pattern that the datetime value should follow. Defaults to 'MM/dd/yyyy hh:mm'.
Please see CDateTimeParser for details about how to specify a datetime format.
This property is effective only when type is 'datetime'.
public string $timeFormat;
the format pattern that the time value should follow. Defaults to 'hh:mm'.
Please see CDateTimeParser for details about how to specify a time format.
This property is effective only when type is 'time'.
public string $type;
the data type that the attribute should be. Defaults to 'string'.
Valid values include 'string', 'integer', 'float', 'array', 'date', 'time' and 'datetime'.
Note that 'time' and 'datetime' have been available since version 1.0.5.
Method Details
protected void validateAttribute( CModel $object, string $attribute)
|
| $object |
CModel |
the object being validated |
| $attribute |
string |
the attribute being validated |
Validates the attribute of the object.
If there is any error, the error message is added to the object.