Last active
December 14, 2015 02:49
-
-
Save phalcon/5016248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Phalcon\Validation\Validator\PresenceOf; | |
| use Phalcon\Validation\Validator\StringLength; | |
| $validation = new Phalcon\Validation(); | |
| $validation->add('name', new PresenceOf([ | |
| 'message' => 'The name is required' | |
| ]); | |
| $validation->add('name', new StringLength([ | |
| 'min' => 5, | |
| 'messageMinimum' => 'The name is too short', | |
| 'max' => 10, | |
| 'messageMaximum' => 'The name is too long', | |
| ]); | |
| $validation->add('created', new Regex([ | |
| 'format' => '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/', | |
| 'message' => 'The date is not valid' | |
| ]); | |
| $messages = $validation->validate($_POST); | |
| if (count($messages) { | |
| foreach ($messages as $message) { | |
| echo $message, PHP_EOL; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment