Re: SSN Validation Class
| From: | Brent Cook | Date: | Mon, 10 Jun 2002 06:24:18 +0000 |
| Subject: | Re: SSN Validation Class | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-6827@lists.php.net to get a copy of this message | ||
On Sat, 8 Jun 2002, Tomas V.V.Cox wrote:
> Cool Brent, I've just commited it with some CS retouchs :-)
Thanks. I tend to be spare with the old curlie wurlies. (been reading
clockwork orange)
> BTW, I've extended a little the ssnGetHighGroups() method for accepting
> more flexible sources (for ex a locally mirrored file or directly the
> contents if come from a cache handling system).
Sounds fine. It would be best to cache a prepared array and not use
ssnGetHighGroups at all if the data is cached, but I'm all for
flexibility.
> I was thinking more in the integration with the multiple method, and
> it's very possible that I change the class definition to Validate_ISO
> instead of ValidateISO. So we could introduce an autoloader mechanism
> in multiple() with:
>
> $options = array(
> 'ssn' => array('type' => 'us_ssn', ..)
> )
>
> // $val_method in the form "<class name><underscore><method name>"
> if (strpos('_', $val_method) !== false) {
> list($class, $method) = explode('_', $val_method);
> include_once "Validate/$class.php";
> call_user_func(array("Validate_$class", $method), $args));
> }
At first, I didn't know what you were talking about here, but then I read
Validate.php actually (heh), and it looks fine to me. So, if multiple, and
possiblly a 'single' function, of the form:
Validate::single($variable, array('type'=>'whatever', ...);
become the de rigueur ways of using Validate (as opposed to calling
individual methods), then this is the way to go. So, will people go for
it? If it doesn't incur an important performance penalty, sure. Checking a
web form is a good example of an easy win. But, say you were analysing a
big database. Using a method like this might be a performance hit, since
it has to translate every call to a validation method one-by-one.
Indirection is great, but it'll take some field trials before its clear
that the benefit outweighs the risks. If people subvert an autoloader
mechanism, should we care? If we design the classes with an autoloader in
mind, do it hurt those who don't want it? Just brainstorming.
- Brent
> Will take a look.
>
>
> Tomas V.V.Cox
>
> PS.- Thanks for the package.xml file :-)
>
>
> Brent Cook wrote:
> >
> > Okee dokey,
> >
> > This is the validation class for SSNs. This is how it might be used:
> >
> > include 'Validate/US.php';
> > $test_numbers = array
> > ('123-23-2313','463911234','123-45-6789',
> >
> > '000-11-1111','111-00-1231','123-03-3434',
> > '999-12-3452', '743-99-2311');
> >
> > $ssn_high_groups = ValidateUS::ssnGetHighGroups();
> >
> > foreach ($test_numbers as $number) {
> > echo $number.' is ';
> > if (ValidateUS::ssn($number, $ssn_high_groups))
> > echo "Valid\n";
> > else
> > echo "Invalid\n";
> > }
> >
> > It is intended to be placed where Tomas indicated, in Validation. Enjoy.
> > You can use it without passing the list of high ssn group numbers, but it
> > then pulls that data every time from the SSA webpage.
> >
> > - Brent
> >
> > ------------------------------------------------------------------------
> > Name: US.php
> > US.php Type: Plain Text (TEXT/PLAIN)
> > Encoding: BASE64
> >
> > Name: package.xml
> > package.xml Type: Plain Text (TEXT/PLAIN)
> > Encoding: BASE64
>