内置验证器
PresenceOf - 验证值不为 null 或空字符串
$validator->add('name', new \Phalcon\Validation\Validator\PresenceOf([
'message' => 'The name is required'
]));
电子邮件 - 检查值是否具有正确的电子邮件格式
$validator->add('email', new \Phalcon\Validation\Validator\Email([
'message' => 'The e-mail is not valid'
]));
相同 - 检查值是否与其他值相同
$validator->add('terms', new \Phalcon\Validation\Validator\Identical([
'accepted' => 'yes',
'message' => 'Terms and conditions must be accepted'
]));
Url - 检查值是否具有 url 格式
$validator->add('url', new \Phalcon\Validation\Validator\Url([
'message' => ':field must be a url'
]));
确认 - 检查两个值是否具有相同的值
$validator->add('password', new \Phalcon\Validation\Validator\Confirmation([
'message' => 'Password doesn\'t match confirmation',
'with' => 'confirmPassword'
]));
StringLength - 验证字符串是否具有指定的最大和最小约束如果字符串的长度为 L,min <= L <= max,则传递测试,即 L 必须至少为 min,并且最多为 max。
$validation->add('name_last', new \Phalcon\Validation\Validator\StringLength([
'max' => 50,
'min' => 2,
'messageMaximum' => 'We don\'t like really long names',
'messageMinimum' => 'We want more than just their initials'
]));
正则表达式 - 允许验证字段的值是否与正则表达式匹配
$validator->add('created_at', new \Phalcon\Validation\Validator\Regex([
'pattern' => '/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/',
'message' => 'The creation date is invalid'
]));
CreditCard - 检查值是否具有有效的信用卡号
$validator->add('creditcard', new \Phalcon\Validation\Validator\CreditCard([
'message' => 'The credit card number is not valid'
]));
Between - 验证值是否包含两个值的包含范围。对于值 x,如果最小值<= x <=最大值,则通过测试。
$validator->add('name', new \Phalcon\Validation\Validator\Between([
'minimum' => 0,
'maximum' => 100,
'message' => 'The price must be between 0 and 100'
]));
ExclusionIn - 检查值是否未包含在值列表中
$validator->add('status', new \Phalcon\Validation\Validator\ExclusionIn([
'message' => 'The status must not be A or B',
'domain' => ['A', 'B']
]));
InclusionIn - 检查值是否包含在值列表中
$validator->add('status', new \Phalcon\Validation\Validator\InclusionIn([
'message' => 'The status must be A or B',
'domain' => ['A', 'B']
]));
唯一性 - 检查值是否是唯一性
$validator->add('login', new \Phalcon\Validation\Validator\Uniqueness([
'message' => 'The login must be unique',
'model' => new Users()
]));