Validation functions
| From: | Michael Dransfield | Date: | Sat, 22 Jun 2002 15:44:03 +0000 |
| Subject: | Validation functions | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-7288@lists.php.net to get a copy of this message | ||
I have written a Validate_UK class which can check for valid uk postcodes and NI numbers (ssn) and it struck me that the way that Validate is structured means it is difficult to validate a post/zip code / ssn from
ANYWHERE. Ive put together a rough function which i think should be included into the main Validate class. It relies on each of the country specific objects being named consistantly, and there being a method called getZipValFunc(), this will return a string with the name of the function to validate postcodes, which can be anything that the author chooses. This function must return bool if it is valid or not, or an error.This will make things much easier, since a lot of web forms capture data from many different countries, the current system would involve quite a lot of work to validate a postcode or ssn, first checking the object for the exact function, then writing custom code for each country. We can add other global functions such as tel, and ssn even if they are very basic (count how many numbers) functions. This function hasnt been tested and some of the file paths might be incorrect, I am developing on windows and so therefore dont have a working pear and Im just usinging them as regular classes. What should I do to add my UK extension? function zipcode($zip, $cc){
if (file_exists("Validate/$cc.php")){
require_once("Validate/$cc.php");
$vn = "Validate_$cc"
$vo = new $vn();
$zvf = $vo->getZipValFunc();
if (function_exists($zvf)){
return $zvf($zip);
}
else {
return new PEAR_Error('unable to validate - no function', 2,PEAR_ERROR_TRIGGER, E_USER_NOTICE);
}
}
else {
return new PEAR_Error('Unable to validate - no file', 1, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
}
}