独立验证

任何时候,都可以使用 Validate 类进行独立的验证操作,例如:

  1. $validate = Validate::instance();
  2. $rule = array(
  3. 'user_id' => array(
  4. 'require' => true,
  5. 'format' => 'int',
  6. ),
  7. 'user_name' => array(
  8. 'length' => '1,30',
  9. 'format' => 'alpha_dash',
  10. ),
  11. );
  12. $validate->rule($rule);
  13. $data = [
  14. 'name' => 'baigo',
  15. 'email' => 'baigo@qq.com'
  16. ];
  17. if (!$validate->verify($data)) {
  18. print_r($validate->getMessage());
  19. }