Created
October 17, 2011 18:19
-
-
Save qzio/1293347 to your computer and use it in GitHub Desktop.
validator api
This file contains 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 | |
$a = array("name" => "simon", "email" => "[email protected]", "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