Skip to content

Instantly share code, notes, and snippets.

@phalcon
Last active December 14, 2015 02:49
Show Gist options
  • Select an option

  • Save phalcon/5016248 to your computer and use it in GitHub Desktop.

Select an option

Save phalcon/5016248 to your computer and use it in GitHub Desktop.
<?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