Re: Validation class method

From: Date: Thu, 06 Jun 2002 16:05:24 +0000
Subject: Re: Validation class method
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6746@lists.php.net to get a copy of this message
That's a good idea. What do you think about this simpler version? function ssn($inbound) { // remove any dashes, spaces, returns, tabs or slashes $inbound = str_replace(array('-','/',' ',"\t","\n"),'',$inbound); // check if this is a 9-digit number return (is_int($inbound) && (strlen($inbound) == 9)); } - Brent On Thu, 6 Jun 2002, Tim Gallagher wrote: > Tomas, > > I've written a US SSN (social security number) validator for my own > uses. I thought you might want to include it in the validation class. > > -timmyg > > > /** > * Validates a string to see if it is a valid social security number. > * Returns true on valid social security number. > * @access public > * @parameter string The string to test. > * @returns boolean True on valid ssn, False otherwise. > * @author Tim Gallagher<timg@sunflowerroad.com> > */ > function ssn($inbound) > { > if (strpos($inbound, "-") === FALSE) { > // the social security number has no dashes. check length and > numericity only. > } else { > //get rid of the dashes, then check. > $inbound = implode("",explode("-",$inbound)); > }; // end if > > if ( ereg("^([0-9]{9})$", $inbound )) { > return TRUE; > } else { > return FALSE; > }; // end if > } // end method > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.pear.dev (#6746) next »