Phalcon\Validation\Validator\Alnum
#只能包含字母、数字、字符
Phalcon\Validation\Validator\Alpha
#只能包含字母
Phalcon\Validation\Validator\Between
#介于二者之间,minimum<=x<=maximum
#示例
validator->add('name', new Between(array(
'minimum' => 0,
'maximum' => 100,
'message' => 'The price must be between 0 and 100'
)));
Phalcon\Validation\Validator\Confirmation
#检测二个值必须一样
#示例
$validator->add('password', new Confirmation(array(
'message' => 'Password doesn\'t match confirmation',
'with' => 'confirmPassword'
)));
Phalcon\Validation\Validator\Digit
#数字字符,Check for numeric character(s)
Phalcon\Validation\Validator\Email
#email
Phalcon\Validation\Validator\ExclusionIn
#在指定值之外
#示例
$validator->add('status', new ExclusionIn(array(
'message' => 'The status must not be A or B',
'domain' => array('A', 'B')
)));
Phalcon\Validation\Validator\File
#文件属性检测
#示例
$validator->add('file', new FileValidator(array(
'maxSize' => '2M', //文件最大限制
'messageSize' => ':field exceeds the max filesize (:max)', //超出大小的提示
'allowedTypes' => array('image/jpeg', 'image/png'), //允许文件类型
'messageType' => 'Allowed file types are :types', //超出允许文件类型提示
'maxResolution' => '800x600', //如果是图片,不能超出的尺寸
'messageMaxResolution' => 'Max resolution of :field is :max'
)));
Phalcon\Validation\Validator\Identical
#等于固定某值
#示例
$validator->add('terms', new Identical(array(
'accepted' => 'yes',
'message' => 'Terms and conditions must be accepted'
)));
Phalcon\Validation\Validator\InclusionIn
#在指定值内
#示例
$validator->add('status', new InclusionIn(array(
'message' => 'The status must be A or B',
'domain' => array('A', 'B')
)));
Phalcon\Validation\Validator\Numericality
#为数字类型,与Digit不同的是这个是检测是否为数字类型
Phalcon\Validation\Validator\PresenceOf
#检测是否为空,not null or empty string
Phalcon\Validation\Validator\Regex
#正则表达式验证
#示例
$validator->add('created_at', new RegexValidator(array(
'pattern' => '/^[0-9]{4}[-\/](0[1-9]¦1[12])[-\/](0[1-9]¦[12][0-9]¦3[01])$/',
'message' => 'The creation date is invalid'
)));
Phalcon\Validation\Validator\StringLength
#检测字符长度
#示例
$validation->add('name_last', new StringLength(array(
'max' => 50,
'min' => 2,
'messageMaximum' => 'We don\'t like really long names',
'messageMinimum' => 'We want more than just their initials'
)));
Phalcon\Validation\Validator\Uniquenes
#值是否在指定的数据库表中
#示例1
$validator->add('username', new Uniqueness(array(
'model' => 'Users',
'message' => ':field must be unique'
)));
#示例2,用attribute映射字段
$validator->add('username', new UniquenessValidator(array(
'model' => 'Users',
'attribute' => 'nick'
)));
Phalcon\Validation\Validator\Url
#为url
相关博文
phalcon内置验证(非model)