Skip to content

Instantly share code, notes, and snippets.

@qzio
Created October 17, 2011 18:19
Show Gist options
  • Save qzio/1293347 to your computer and use it in GitHub Desktop.
Save qzio/1293347 to your computer and use it in GitHub Desktop.
validator api
<?php
$a = array("name" => "simon", "email" => "simon@noona.se", "homepage" => "http:////**sunet.se", "age" => "twentynine");
$validate = new Validator($a);
$validate->ensure("name", "")->isLen(5)->isAlpha();
$validate->ensure("email")->isEmail();
$validate->ensure("homepage", "Homepage is wr00ng!")->isUrl();
$validate->ensure("age")->isInt();
$validationErrors = $validate->errors(); // array(array("age" => "Age is not valid"), array("homepage" => "Homepage is wr00ng!"));
try {
$validate->ensureValidated();
} catch(Validator_Exception $e) {
echo "there is errors!!!";
}
if ( $validate->hasErrors() ) {
echo "yepp, there is errors in the validate object";
echo "see: ".print_r($validate->errors(),true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment