Zend Framework - Validators Example


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $validators = array(
  2. 'address' => array('Alnum', new Zend_Validate_Alnum(true),
  3. 'messages' => array(
  4. 'Address not valid', // Default error message
  5. // Specific error messages
  6. array(Zend_Validate_Alnum::NOT_ALNUM =>
  7. 'Address contains invalid characters',
  8. Zend_Validate_Alnum::STRING_EMPTY =>
  9. 'Address field is mandatory'))),
  10. 'phone' => array('Digits', new Zend_Validate_Digits(),
  11. 'messages' => array(
  12. 'Wrong phone number format',
  13. array(Zend_Validate_Digits::NOT_DIGITS =>
  14. 'Phone number can only have digits',
  15. Zend_Validate_Digits::STRING_EMPTY =>
  16. 'Phone number can not be empty'))),
  17. 'age' => array('Digits', new Zend_Validate_Between(16, 59),
  18. 'messages' => array(
  19. 'You do not qualify because of your age',
  20. array(Zend_Validate_Between::NOT_BETWEEN =>
  21. 'Age is not between the allowed range'))),
  22. 'id' => array('StringLength', new Zend_Validate_StringLength(8, 10),
  23. 'messages' => array(
  24. 'ID not valid',
  25. array(Zend_Validate_StringLength::TOO_LONG =>
  26. 'ID is too long',
  27. Zend_Validate_StringLength::TOO_SHORT =>
  28. 'ID is too short'))),
  29. 'date' => array('Date', new Zend_Validate_Date(),
  30. 'messages' => array(
  31. 'Wrong date',
  32. array(Zend_Validate_Date::INVALID =>
  33. 'Date not recognized as valid',
  34. Zend_Validate_Date::FALSEFORMAT =>
  35. 'Date format is incorrect',
  36. Zend_Validate_Date::NOT_YYYY_MM_DD =>
  37. 'Date format must be YYYY-MM-DD'))),
  38. 'url' => $validurl
  39. );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.