Return to Snippet

Revision: 31010
at August 27, 2010 08:17 by paramah


Initial Code
$validators = array( 
             'address' => array('Alnum', new Zend_Validate_Alnum(true), 
                                'messages' => array( 
                                'Address not valid', // Default error message 
                                // Specific error messages 
                                array(Zend_Validate_Alnum::NOT_ALNUM => 
                                      'Address contains invalid characters', 
                                      Zend_Validate_Alnum::STRING_EMPTY => 
                                      'Address field is mandatory'))), 
             'phone'   => array('Digits', new Zend_Validate_Digits(), 
                                'messages' => array( 
                                'Wrong phone number format', 
                                array(Zend_Validate_Digits::NOT_DIGITS => 
                                      'Phone number can only have digits', 
                                      Zend_Validate_Digits::STRING_EMPTY => 
                                      'Phone number can not be empty'))), 
             'age'     => array('Digits', new Zend_Validate_Between(16, 59), 
                                'messages' => array( 
                                'You do not qualify because of your age', 
                                array(Zend_Validate_Between::NOT_BETWEEN => 
                                      'Age is not between the allowed range'))), 
             'id'      => array('StringLength', new Zend_Validate_StringLength(8, 10), 
                                'messages' => array( 
                                'ID not valid', 
                                array(Zend_Validate_StringLength::TOO_LONG => 
                                      'ID is too long', 
                                      Zend_Validate_StringLength::TOO_SHORT => 
                                      'ID is too short'))), 
             'date'    => array('Date', new Zend_Validate_Date(), 
                                'messages' => array( 
                                'Wrong date', 
                                array(Zend_Validate_Date::INVALID => 
                                      'Date not recognized as valid', 
                                      Zend_Validate_Date::FALSEFORMAT => 
                                      'Date format is incorrect', 
                                      Zend_Validate_Date::NOT_YYYY_MM_DD => 
                                     'Date format must be YYYY-MM-DD'))), 
              'url'      => $validurl 
           );

Initial URL

                                

Initial Description

                                

Initial Title
Zend Framework - Validators Example

Initial Tags

                                

Initial Language
PHP