內建驗證器
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()
]));