// example code for usage of the validation library
// find library code at http://validation-php.googlecode.com/svn/trunk/src/Validator/
$request = new Request_Raw(array('username' => 'testervih.dk'));
$validator = new Validator;
$validator->addBasicValidator(new Rule_Email('username'), 'email is not valid');
if (!$validator->validate($request)) {
print_r($validator->getErrors());
} else {
echo $validator->getCleanRequest()->get('username');
}
Refactorings
No refactoring yet !
zaadjis
October 12, 2007, October 12, 2007 07:53, permalink
Don't reinvent. Google, try, extend (if needed).
http://framework.zend.com/manual/en/zend.validate.html
http://pear.php.net/package/Validate
http://ez.no/doc/components/view/latest/(file)/introduction_UserInput.html
http://php.net/filter_input_array
<?php
if (!filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)) {
$errors[] = 'email invalid';
}
I am trying to wrap my head around creating a reusable validation. I came up with the following pretty much inspired by a book written by Reiersol. You can find the full code library on http://code.google.com/p/validation-php/
The code is the example usage of the open source validation library.