cvs: pear /Validate/Validate AT.php CH.php DE.php FR.php NL.php UK.php US.php ptBR.php /Validate/tests validate_AT.php validate_CH.php
validate_DE.php validate_NL.php validate_UK.php
| From: | Helgi �ormar �orbj�rnsson | Date: | Wed, 15 Dec 2004 12:58:00 +0000 |
| Subject: | cvs: pear /Validate/Validate AT.php CH.php DE.php FR.php NL.php UK.php US.php ptBR.php /Validate/tests validate_AT.php validate_CH.php validate_DE.php validate_NL.php validate_UK.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-27428@lists.php.net to get a copy of this message | ||
dufuz Wed Dec 15 07:58:00 2004 EDT
Modified files:
/pear/Validate/tests validate_AT.php validate_CH.php
validate_DE.php validate_NL.php
validate_UK.php
/pear/Validate/Validate AT.php CH.php DE.php FR.php NL.php ptBR.php
UK.php US.php
Log:
Request #2200 but slightly modified, BC break! postcode (and function with it's local name)
named to postalCode, tests updated to reflect that, region added to US and FR
http://cvs.php.net/diff.php/pear/Validate/tests/validate_AT.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/tests/validate_AT.php diff -u pear/Validate/tests/validate_AT.php:1.3 pear/Validate/tests/validate_AT.php:1.4 --- pear/Validate/tests/validate_AT.php:1.3 Tue Feb 3 18:34:53 2004 +++ pear/Validate/tests/validate_AT.php Wed Dec 15 07:58:00 2004 @@ -11,16 +11,16 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_AT::postcode(7033, true)); - $this->assertTrue(Validate_AT::postcode(7000, true)); - $this->assertTrue(Validate_AT::postcode(4664, true)); - $this->assertTrue(Validate_AT::postcode(2491, true)); - $this->assertFalse(Validate_AT::postcode(1000, true)); - $this->assertFalse(Validate_AT::postcode(9999, true)); - $this->assertFalse(Validate_AT::postcode('abc', true)); - $this->assertFalse(Validate_AT::postcode('a7000', true)); + $this->assertTrue(Validate_AT::postalCode(7033, true)); + $this->assertTrue(Validate_AT::postalCode(7000, true)); + $this->assertTrue(Validate_AT::postalCode(4664, true)); + $this->assertTrue(Validate_AT::postalCode(2491, true)); + $this->assertFalse(Validate_AT::postalCode(1000, true)); + $this->assertFalse(Validate_AT::postalCode(9999, true)); + $this->assertFalse(Validate_AT::postalCode('abc', true)); + $this->assertFalse(Validate_AT::postalCode('a7000', true)); } function testssn() http://cvs.php.net/diff.php/pear/Validate/tests/validate_CH.php?r1=1.2&r2=1.3&ty=u Index: pear/Validate/tests/validate_CH.php diff -u pear/Validate/tests/validate_CH.php:1.2 pear/Validate/tests/validate_CH.php:1.3 --- pear/Validate/tests/validate_CH.php:1.2 Tue Feb 3 18:34:53 2004 +++ pear/Validate/tests/validate_CH.php Wed Dec 15 07:58:00 2004 @@ -1,5 +1,5 @@ <?php -// $Id: validate_CH.php,v 1.2 2004/02/03 23:34:53 neufeind Exp $ +// $Id: validate_CH.php,v 1.3 2004/12/15 12:58:00 dufuz Exp $ require_once 'PHPUnit.php'; require_once 'Validate/CH.php'; @@ -12,11 +12,11 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_CH::postcode('9658', true)); - $this->assertFalse(Validate_CH::postcode('9654', true)); - $this->assertFalse(Validate_CH::postcode('96c4', true)); + $this->assertTrue(Validate_CH::postalCode('9658', true)); + $this->assertFalse(Validate_CH::postalCode('9654', true)); + $this->assertFalse(Validate_CH::postalCode('96c4', true)); } function testssn() http://cvs.php.net/diff.php/pear/Validate/tests/validate_DE.php?r1=1.1&r2=1.2&ty=u Index: pear/Validate/tests/validate_DE.php diff -u pear/Validate/tests/validate_DE.php:1.1 pear/Validate/tests/validate_DE.php:1.2 --- pear/Validate/tests/validate_DE.php:1.1 Wed Feb 25 13:53:09 2004 +++ pear/Validate/tests/validate_DE.php Wed Dec 15 07:58:00 2004 @@ -1,5 +1,5 @@ <?php -// $Id: validate_DE.php,v 1.1 2004/02/25 18:53:09 neufeind Exp $ +// $Id: validate_DE.php,v 1.2 2004/12/15 12:58:00 dufuz Exp $ require_once 'PHPUnit.php'; require_once 'Validate/DE.php'; @@ -12,14 +12,14 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_DE::postcode('10115')); - $this->assertTrue(Validate_DE::postcode('09111')); - $this->assertTrue(Validate_DE::postcode('80331')); - $this->assertFalse(Validate_DE::postcode('0115')); - $this->assertFalse(Validate_DE::postcode('101154')); - $this->assertFalse(Validate_DE::postcode('x1154')); + $this->assertTrue(Validate_DE::postalCode('10115')); + $this->assertTrue(Validate_DE::postalCode('09111')); + $this->assertTrue(Validate_DE::postalCode('80331')); + $this->assertFalse(Validate_DE::postalCode('0115')); + $this->assertFalse(Validate_DE::postalCode('101154')); + $this->assertFalse(Validate_DE::postalCode('x1154')); } function testbankcode() http://cvs.php.net/diff.php/pear/Validate/tests/validate_NL.php?r1=1.4&r2=1.5&ty=u Index: pear/Validate/tests/validate_NL.php diff -u pear/Validate/tests/validate_NL.php:1.4 pear/Validate/tests/validate_NL.php:1.5 --- pear/Validate/tests/validate_NL.php:1.4 Wed Dec 10 09:35:05 2003 +++ pear/Validate/tests/validate_NL.php Wed Dec 15 07:58:00 2004 @@ -4,7 +4,7 @@ class Validate_NL_Test extends PHPUnit_TestCase { - var $postcodes = array( + var $postalCodes = array( "1234 AB" => true, "1234 ab" => true, "1234AB" => true, @@ -40,7 +40,7 @@ "640400231" => false ); - function Validate_NL_Test( $name ) + function Validate_NL_Test($name) { $this->PHPUnit_TestCase($name); } @@ -54,17 +54,17 @@ { } - function testPostcode() + function testpostalCode() { - foreach ($this->postcodes as $postcode=>$expected_result){ - $r = Validate_NL::postcode($postcode); + foreach ($this->postalCodes as $postalCode => $expected_result) { + $r = Validate_NL::postalCode($postalCode); $this->assertEquals($r, $expected_result); } } function testPhone() { - foreach ($this->phonenumbers as $phonenumber=>$data){ + foreach ($this->phonenumbers as $phonenumber => $data) { $r = Validate_NL::phonenumber($phonenumber, $data[0]); $this->assertEquals($r, $data[1]); } @@ -72,7 +72,7 @@ function testSSN() { - foreach ($this->ssns as $ssn=>$expected_result){ + foreach ($this->ssns as $ssn => $expected_result) { $r = Validate_NL::SSN($ssn); $this->assertEquals($r, $expected_result); } @@ -80,7 +80,7 @@ function testBankAccount() { - foreach ($this->bank_accounts as $account=>$expected_result){ + foreach ($this->bank_accounts as $account => $expected_result) { $r = Validate_NL::bankAccountNumber($account); $this->assertEquals($r, $expected_result); } @@ -88,7 +88,7 @@ } // runs the tests -$suite = new PHPUnit_TestSuite("Validate_NL_Test"); +$suite = new PHPUnit_TestSuite('Validate_NL_Test'); $result = PHPUnit::run($suite); // prints the tests echo $result->toString(); http://cvs.php.net/diff.php/pear/Validate/tests/validate_UK.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/tests/validate_UK.php diff -u pear/Validate/tests/validate_UK.php:1.3 pear/Validate/tests/validate_UK.php:1.4 --- pear/Validate/tests/validate_UK.php:1.3 Mon Mar 8 15:11:57 2004 +++ pear/Validate/tests/validate_UK.php Wed Dec 15 07:58:00 2004 @@ -4,8 +4,8 @@ class Validate_UK_Test extends PHPUnit_TestCase { - var $postcodes = array( - /* some test-cases from the original of the postcode-check */ + var $postalCodes = array( + /* some test-cases from the original of the postalCode-check */ 'BS25 1NB' => true, 'B5 5TF' => true, '5Ty6tty' => false, @@ -79,10 +79,10 @@ { } - function testPostcode() + function testpostalCode() { - foreach ($this->postcodes as $postcode=>$expected_result){ - $r = Validate_UK::postcode($postcode); + foreach ($this->postalCodes as $postalCode=>$expected_result){ + $r = Validate_UK::postalCode($postalCode); $this->assertEquals($r, $expected_result); } } http://cvs.php.net/diff.php/pear/Validate/Validate/AT.php?r1=1.7&r2=1.8&ty=u Index: pear/Validate/Validate/AT.php diff -u pear/Validate/Validate/AT.php:1.7 pear/Validate/Validate/AT.php:1.8 --- pear/Validate/Validate/AT.php:1.7 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/AT.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Copyright (c) 2003 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: AT.php,v 1.7 2004/11/08 09:17:48 dufuz Exp $ +// $Id: AT.php,v 1.8 2004/12/15 12:58:00 dufuz Exp $ /** * Requires Validate @@ -30,7 +30,7 @@ * @package Validate * @category PHP * -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * @access public */ class Validate_AT @@ -44,7 +44,7 @@ * @param bool optional; strong checks (e.g. against a list of postcodes) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { if ($strong) { static $postcodes; @@ -55,9 +55,8 @@ } return in_array((int) $postcode, $postcodes); - } else { - return (ereg('^[0-9]{4}$', $postcode)); } + return (ereg('^[0-9]{4}$', $postcode)); } /** http://cvs.php.net/diff.php/pear/Validate/Validate/CH.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/Validate/CH.php diff -u pear/Validate/Validate/CH.php:1.3 pear/Validate/Validate/CH.php:1.4 --- pear/Validate/Validate/CH.php:1.3 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/CH.php Wed Dec 15 07:58:00 2004 @@ -16,12 +16,12 @@ // | Copyright (c) 2004 Hans-Peter Oeri <hp@oeri.ch> | // +----------------------------------------------------------------------+ // -// $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +// $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ /** * Validation functions for Swiss IDs * -* @version $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +* @version $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ * @author Hans-Peter Oeri <hp@oeri.ch> * @copyright Copyright (c) 2004, Hans-Peter Oeri <hp@oeri.ch> * @license PHP @@ -36,7 +36,7 @@ * Validate_CH * * @access public -* @version $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +* @version $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ */ class Validate_CH { @@ -123,7 +123,7 @@ * @param bool optional; strong checks (e.g. against a list of postcodes) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong=false) + function postalCode($postcode, $strong = false) { if ($strong) { static $postcodes; @@ -134,9 +134,8 @@ } return in_array($postcode, $postcodes); - } else { - return (ereg('^[0-9]{4}$', $postcode)); } + return (ereg('^[0-9]{4}$', $postcode)); } } ?> http://cvs.php.net/diff.php/pear/Validate/Validate/DE.php?r1=1.5&r2=1.6&ty=u Index: pear/Validate/Validate/DE.php diff -u pear/Validate/Validate/DE.php:1.5 pear/Validate/Validate/DE.php:1.6 --- pear/Validate/Validate/DE.php:1.5 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/DE.php Wed Dec 15 07:58:00 2004 @@ -27,10 +27,10 @@ * Validate a German postcode * * @param string postcode to validate - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/FR.php?r1=1.11&r2=1.12&ty=u Index: pear/Validate/Validate/FR.php diff -u pear/Validate/Validate/FR.php:1.11 pear/Validate/Validate/FR.php:1.12 --- pear/Validate/Validate/FR.php:1.11 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/FR.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Pierre-Alain Joye <paj@pearfr.org> | // +----------------------------------------------------------------------+ // -// $Id: FR.php,v 1.11 2004/11/08 09:17:48 dufuz Exp $ +// $Id: FR.php,v 1.12 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in France @@ -206,5 +206,53 @@ } return (($sum % 10) == 0); } + + /** + * Validates a French Postal Code format + * + * @param string $postalCode the code to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) + * @return boolean TRUE if code is valid, FALSE otherwise + * @access public + * @static + * @todo Validate against department + */ + function postalCode($postalCode, $strong = false) + { + return (bool) preg_match('/^[0-9]{5}$/', $postalCode); + } + + /** + * Validates a French "departement" + * + * @param string $region 2-digit department number + * @return bool Whether the department is valid + * @static + */ + function region($region) + { + if (is_numeric($region) + && floor($region) == ceil($region)) { + switch (strlen($region)) { + case 2: + if ($region >= 1 && $region <= 95 + && $region != 20)) { + return true; + } + break; + case 3: + if ($region >= 971 && $region <= 975) { + return true; + } + break; + } + } + switch (strtoupper($region)) { + case '2A': + case '2B': + return true; + } + return false; + } } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Validate/Validate/NL.php?r1=1.8&r2=1.9&ty=u Index: pear/Validate/Validate/NL.php diff -u pear/Validate/Validate/NL.php:1.8 pear/Validate/Validate/NL.php:1.9 --- pear/Validate/Validate/NL.php:1.8 Mon Nov 8 04:17:49 2004 +++ pear/Validate/Validate/NL.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Dave Mertens <zyprexia@php.net> | // +----------------------------------------------------------------------+ // -// $Id: NL.php,v 1.8 2004/11/08 09:17:49 dufuz Exp $ +// $Id: NL.php,v 1.9 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in NL // @@ -33,10 +33,10 @@ * Validate a NL postcode * * @param string $postcode NL postcode to validate - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/ptBR.php?r1=1.2&r2=1.3&ty=u Index: pear/Validate/Validate/ptBR.php diff -u pear/Validate/Validate/ptBR.php:1.2 pear/Validate/Validate/ptBR.php:1.3 --- pear/Validate/Validate/ptBR.php:1.2 Tue Feb 3 18:34:53 2004 +++ pear/Validate/Validate/ptBR.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Silvano Girardi Jr. <silvano@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ptBR.php,v 1.2 2004/02/03 23:34:53 neufeind Exp $ +// $Id: ptBR.php,v 1.3 2004/12/15 12:58:00 dufuz Exp $ // Specific validation methods for data used in pt_BR // @@ -27,28 +27,13 @@ * and other languages) * format: xxxxx-xxx * - * @param string $cep pt_BR CEP to validate + * @param string $postalCode pt_BR CEP/postalCode to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if $cep is ok, false otherwise */ - function cep($cep) + function postalCode($postalCode, $strong = false) { - return (ereg('(^[0-9]{5})-([0-9]{3})$', $cep)); - } - - /** - * validates a postcode; alias-function - * - * @access public - * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) - * @return bool - */ - function postcode($postcode, $strong=false) - { - // $strong is not used here at the moment; added for API compatibility - // checks might be added at a later stage - - return cep($postcode); + return (ereg('(^[0-9]{5})-([0-9]{3})$', $postalCode)); } /** http://cvs.php.net/diff.php/pear/Validate/Validate/UK.php?r1=1.13&r2=1.14&ty=u Index: pear/Validate/Validate/UK.php diff -u pear/Validate/Validate/UK.php:1.13 pear/Validate/Validate/UK.php:1.14 --- pear/Validate/Validate/UK.php:1.13 Mon Nov 8 19:40:59 2004 +++ pear/Validate/Validate/UK.php Wed Dec 15 07:58:00 2004 @@ -17,7 +17,7 @@ // | Stefan Neufeind <pear.neufeind@speedpartner.de> | // +----------------------------------------------------------------------+ // -// $Id: UK.php,v 1.13 2004/11/09 00:40:59 dufuz Exp $ +// $Id: UK.php,v 1.14 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in UK @@ -26,7 +26,8 @@ class Validate_UK { // overlay function - function getZipValFunc() { + function getZipValFunc() + { return 'postcode'; } @@ -44,10 +45,10 @@ * * @access public * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/US.php?r1=1.13&r2=1.14&ty=u Index: pear/Validate/Validate/US.php diff -u pear/Validate/Validate/US.php:1.13 pear/Validate/Validate/US.php:1.14 --- pear/Validate/Validate/US.php:1.13 Mon Nov 8 04:17:49 2004 +++ pear/Validate/Validate/US.php Wed Dec 15 07:58:00 2004 @@ -17,7 +17,7 @@ // | Tim Gallagher <timg@sunflowerroad.com> | // +----------------------------------------------------------------------+ // -// $Id: US.php,v 1.13 2004/11/08 09:17:49 dufuz Exp $ +// $Id: US.php,v 1.14 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in the United States // @@ -170,5 +170,86 @@ } return $high_groups; } + + /** + * Validates a US Postal Code format (ZIP code) + * + * @param string $postalCode the ZIP code to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) + * @return boolean TRUE if code is valid, FALSE otherwise + * @access public + * @static + * @todo Integrate with USPS web API + */ + function postalCode($postalCode, $strong = false) + { + return (bool) preg_match('/^[0-9]{5}(-[0-9]{4})?$/', $postalCode); + } + + /** + * Validates a "region" (i.e. state) code + * + * @param string $region 2-letter state code + * @return bool Whether the code is a valid state + * @static + */ + function region($region) + { + switch (strtoupper($region)) { + case 'AL': + case 'AK': + case 'AZ': + case 'AR': + case 'CA': + case 'CO': + case 'CT': + case 'DE': + case 'DC': + case 'FL': + case 'GA': + case 'HI': + case 'ID': + case 'IL': + case 'IN': + case 'IA': + case 'KS': + case 'KY': + case 'LA': + case 'ME': + case 'MD': + case 'MA': + case 'MI': + case 'MN': + case 'MS': + case 'MO': + case 'MT': + case 'NE': + case 'NV': + case 'NH': + case 'NJ': + case 'NM': + case 'NY': + case 'NC': + case 'ND': + case 'OH': + case 'OK': + case 'OR': + case 'PA': + case 'RI': + case 'SC': + case 'SD': + case 'TN': + case 'TX': + case 'UT': + case 'VT': + case 'VA': + case 'WA': + case 'WV': + case 'WI': + case 'WY': + return true; + } + return false; + } } ?>
http://cvs.php.net/diff.php/pear/Validate/tests/validate_AT.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/tests/validate_AT.php diff -u pear/Validate/tests/validate_AT.php:1.3 pear/Validate/tests/validate_AT.php:1.4 --- pear/Validate/tests/validate_AT.php:1.3 Tue Feb 3 18:34:53 2004 +++ pear/Validate/tests/validate_AT.php Wed Dec 15 07:58:00 2004 @@ -11,16 +11,16 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_AT::postcode(7033, true)); - $this->assertTrue(Validate_AT::postcode(7000, true)); - $this->assertTrue(Validate_AT::postcode(4664, true)); - $this->assertTrue(Validate_AT::postcode(2491, true)); - $this->assertFalse(Validate_AT::postcode(1000, true)); - $this->assertFalse(Validate_AT::postcode(9999, true)); - $this->assertFalse(Validate_AT::postcode('abc', true)); - $this->assertFalse(Validate_AT::postcode('a7000', true)); + $this->assertTrue(Validate_AT::postalCode(7033, true)); + $this->assertTrue(Validate_AT::postalCode(7000, true)); + $this->assertTrue(Validate_AT::postalCode(4664, true)); + $this->assertTrue(Validate_AT::postalCode(2491, true)); + $this->assertFalse(Validate_AT::postalCode(1000, true)); + $this->assertFalse(Validate_AT::postalCode(9999, true)); + $this->assertFalse(Validate_AT::postalCode('abc', true)); + $this->assertFalse(Validate_AT::postalCode('a7000', true)); } function testssn() http://cvs.php.net/diff.php/pear/Validate/tests/validate_CH.php?r1=1.2&r2=1.3&ty=u Index: pear/Validate/tests/validate_CH.php diff -u pear/Validate/tests/validate_CH.php:1.2 pear/Validate/tests/validate_CH.php:1.3 --- pear/Validate/tests/validate_CH.php:1.2 Tue Feb 3 18:34:53 2004 +++ pear/Validate/tests/validate_CH.php Wed Dec 15 07:58:00 2004 @@ -1,5 +1,5 @@ <?php -// $Id: validate_CH.php,v 1.2 2004/02/03 23:34:53 neufeind Exp $ +// $Id: validate_CH.php,v 1.3 2004/12/15 12:58:00 dufuz Exp $ require_once 'PHPUnit.php'; require_once 'Validate/CH.php'; @@ -12,11 +12,11 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_CH::postcode('9658', true)); - $this->assertFalse(Validate_CH::postcode('9654', true)); - $this->assertFalse(Validate_CH::postcode('96c4', true)); + $this->assertTrue(Validate_CH::postalCode('9658', true)); + $this->assertFalse(Validate_CH::postalCode('9654', true)); + $this->assertFalse(Validate_CH::postalCode('96c4', true)); } function testssn() http://cvs.php.net/diff.php/pear/Validate/tests/validate_DE.php?r1=1.1&r2=1.2&ty=u Index: pear/Validate/tests/validate_DE.php diff -u pear/Validate/tests/validate_DE.php:1.1 pear/Validate/tests/validate_DE.php:1.2 --- pear/Validate/tests/validate_DE.php:1.1 Wed Feb 25 13:53:09 2004 +++ pear/Validate/tests/validate_DE.php Wed Dec 15 07:58:00 2004 @@ -1,5 +1,5 @@ <?php -// $Id: validate_DE.php,v 1.1 2004/02/25 18:53:09 neufeind Exp $ +// $Id: validate_DE.php,v 1.2 2004/12/15 12:58:00 dufuz Exp $ require_once 'PHPUnit.php'; require_once 'Validate/DE.php'; @@ -12,14 +12,14 @@ function setUp(){} function tearDown(){} - function testpostcode() + function testpostalCode() { - $this->assertTrue(Validate_DE::postcode('10115')); - $this->assertTrue(Validate_DE::postcode('09111')); - $this->assertTrue(Validate_DE::postcode('80331')); - $this->assertFalse(Validate_DE::postcode('0115')); - $this->assertFalse(Validate_DE::postcode('101154')); - $this->assertFalse(Validate_DE::postcode('x1154')); + $this->assertTrue(Validate_DE::postalCode('10115')); + $this->assertTrue(Validate_DE::postalCode('09111')); + $this->assertTrue(Validate_DE::postalCode('80331')); + $this->assertFalse(Validate_DE::postalCode('0115')); + $this->assertFalse(Validate_DE::postalCode('101154')); + $this->assertFalse(Validate_DE::postalCode('x1154')); } function testbankcode() http://cvs.php.net/diff.php/pear/Validate/tests/validate_NL.php?r1=1.4&r2=1.5&ty=u Index: pear/Validate/tests/validate_NL.php diff -u pear/Validate/tests/validate_NL.php:1.4 pear/Validate/tests/validate_NL.php:1.5 --- pear/Validate/tests/validate_NL.php:1.4 Wed Dec 10 09:35:05 2003 +++ pear/Validate/tests/validate_NL.php Wed Dec 15 07:58:00 2004 @@ -4,7 +4,7 @@ class Validate_NL_Test extends PHPUnit_TestCase { - var $postcodes = array( + var $postalCodes = array( "1234 AB" => true, "1234 ab" => true, "1234AB" => true, @@ -40,7 +40,7 @@ "640400231" => false ); - function Validate_NL_Test( $name ) + function Validate_NL_Test($name) { $this->PHPUnit_TestCase($name); } @@ -54,17 +54,17 @@ { } - function testPostcode() + function testpostalCode() { - foreach ($this->postcodes as $postcode=>$expected_result){ - $r = Validate_NL::postcode($postcode); + foreach ($this->postalCodes as $postalCode => $expected_result) { + $r = Validate_NL::postalCode($postalCode); $this->assertEquals($r, $expected_result); } } function testPhone() { - foreach ($this->phonenumbers as $phonenumber=>$data){ + foreach ($this->phonenumbers as $phonenumber => $data) { $r = Validate_NL::phonenumber($phonenumber, $data[0]); $this->assertEquals($r, $data[1]); } @@ -72,7 +72,7 @@ function testSSN() { - foreach ($this->ssns as $ssn=>$expected_result){ + foreach ($this->ssns as $ssn => $expected_result) { $r = Validate_NL::SSN($ssn); $this->assertEquals($r, $expected_result); } @@ -80,7 +80,7 @@ function testBankAccount() { - foreach ($this->bank_accounts as $account=>$expected_result){ + foreach ($this->bank_accounts as $account => $expected_result) { $r = Validate_NL::bankAccountNumber($account); $this->assertEquals($r, $expected_result); } @@ -88,7 +88,7 @@ } // runs the tests -$suite = new PHPUnit_TestSuite("Validate_NL_Test"); +$suite = new PHPUnit_TestSuite('Validate_NL_Test'); $result = PHPUnit::run($suite); // prints the tests echo $result->toString(); http://cvs.php.net/diff.php/pear/Validate/tests/validate_UK.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/tests/validate_UK.php diff -u pear/Validate/tests/validate_UK.php:1.3 pear/Validate/tests/validate_UK.php:1.4 --- pear/Validate/tests/validate_UK.php:1.3 Mon Mar 8 15:11:57 2004 +++ pear/Validate/tests/validate_UK.php Wed Dec 15 07:58:00 2004 @@ -4,8 +4,8 @@ class Validate_UK_Test extends PHPUnit_TestCase { - var $postcodes = array( - /* some test-cases from the original of the postcode-check */ + var $postalCodes = array( + /* some test-cases from the original of the postalCode-check */ 'BS25 1NB' => true, 'B5 5TF' => true, '5Ty6tty' => false, @@ -79,10 +79,10 @@ { } - function testPostcode() + function testpostalCode() { - foreach ($this->postcodes as $postcode=>$expected_result){ - $r = Validate_UK::postcode($postcode); + foreach ($this->postalCodes as $postalCode=>$expected_result){ + $r = Validate_UK::postalCode($postalCode); $this->assertEquals($r, $expected_result); } } http://cvs.php.net/diff.php/pear/Validate/Validate/AT.php?r1=1.7&r2=1.8&ty=u Index: pear/Validate/Validate/AT.php diff -u pear/Validate/Validate/AT.php:1.7 pear/Validate/Validate/AT.php:1.8 --- pear/Validate/Validate/AT.php:1.7 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/AT.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Copyright (c) 2003 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: AT.php,v 1.7 2004/11/08 09:17:48 dufuz Exp $ +// $Id: AT.php,v 1.8 2004/12/15 12:58:00 dufuz Exp $ /** * Requires Validate @@ -30,7 +30,7 @@ * @package Validate * @category PHP * -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * @access public */ class Validate_AT @@ -44,7 +44,7 @@ * @param bool optional; strong checks (e.g. against a list of postcodes) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { if ($strong) { static $postcodes; @@ -55,9 +55,8 @@ } return in_array((int) $postcode, $postcodes); - } else { - return (ereg('^[0-9]{4}$', $postcode)); } + return (ereg('^[0-9]{4}$', $postcode)); } /** http://cvs.php.net/diff.php/pear/Validate/Validate/CH.php?r1=1.3&r2=1.4&ty=u Index: pear/Validate/Validate/CH.php diff -u pear/Validate/Validate/CH.php:1.3 pear/Validate/Validate/CH.php:1.4 --- pear/Validate/Validate/CH.php:1.3 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/CH.php Wed Dec 15 07:58:00 2004 @@ -16,12 +16,12 @@ // | Copyright (c) 2004 Hans-Peter Oeri <hp@oeri.ch> | // +----------------------------------------------------------------------+ // -// $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +// $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ /** * Validation functions for Swiss IDs * -* @version $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +* @version $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ * @author Hans-Peter Oeri <hp@oeri.ch> * @copyright Copyright (c) 2004, Hans-Peter Oeri <hp@oeri.ch> * @license PHP @@ -36,7 +36,7 @@ * Validate_CH * * @access public -* @version $Id: CH.php,v 1.3 2004/11/08 09:17:48 dufuz Exp $ +* @version $Id: CH.php,v 1.4 2004/12/15 12:58:00 dufuz Exp $ */ class Validate_CH { @@ -123,7 +123,7 @@ * @param bool optional; strong checks (e.g. against a list of postcodes) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong=false) + function postalCode($postcode, $strong = false) { if ($strong) { static $postcodes; @@ -134,9 +134,8 @@ } return in_array($postcode, $postcodes); - } else { - return (ereg('^[0-9]{4}$', $postcode)); } + return (ereg('^[0-9]{4}$', $postcode)); } } ?> http://cvs.php.net/diff.php/pear/Validate/Validate/DE.php?r1=1.5&r2=1.6&ty=u Index: pear/Validate/Validate/DE.php diff -u pear/Validate/Validate/DE.php:1.5 pear/Validate/Validate/DE.php:1.6 --- pear/Validate/Validate/DE.php:1.5 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/DE.php Wed Dec 15 07:58:00 2004 @@ -27,10 +27,10 @@ * Validate a German postcode * * @param string postcode to validate - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/FR.php?r1=1.11&r2=1.12&ty=u Index: pear/Validate/Validate/FR.php diff -u pear/Validate/Validate/FR.php:1.11 pear/Validate/Validate/FR.php:1.12 --- pear/Validate/Validate/FR.php:1.11 Mon Nov 8 04:17:48 2004 +++ pear/Validate/Validate/FR.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Pierre-Alain Joye <paj@pearfr.org> | // +----------------------------------------------------------------------+ // -// $Id: FR.php,v 1.11 2004/11/08 09:17:48 dufuz Exp $ +// $Id: FR.php,v 1.12 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in France @@ -206,5 +206,53 @@ } return (($sum % 10) == 0); } + + /** + * Validates a French Postal Code format + * + * @param string $postalCode the code to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) + * @return boolean TRUE if code is valid, FALSE otherwise + * @access public + * @static + * @todo Validate against department + */ + function postalCode($postalCode, $strong = false) + { + return (bool) preg_match('/^[0-9]{5}$/', $postalCode); + } + + /** + * Validates a French "departement" + * + * @param string $region 2-digit department number + * @return bool Whether the department is valid + * @static + */ + function region($region) + { + if (is_numeric($region) + && floor($region) == ceil($region)) { + switch (strlen($region)) { + case 2: + if ($region >= 1 && $region <= 95 + && $region != 20)) { + return true; + } + break; + case 3: + if ($region >= 971 && $region <= 975) { + return true; + } + break; + } + } + switch (strtoupper($region)) { + case '2A': + case '2B': + return true; + } + return false; + } } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/Validate/Validate/NL.php?r1=1.8&r2=1.9&ty=u Index: pear/Validate/Validate/NL.php diff -u pear/Validate/Validate/NL.php:1.8 pear/Validate/Validate/NL.php:1.9 --- pear/Validate/Validate/NL.php:1.8 Mon Nov 8 04:17:49 2004 +++ pear/Validate/Validate/NL.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Dave Mertens <zyprexia@php.net> | // +----------------------------------------------------------------------+ // -// $Id: NL.php,v 1.8 2004/11/08 09:17:49 dufuz Exp $ +// $Id: NL.php,v 1.9 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in NL // @@ -33,10 +33,10 @@ * Validate a NL postcode * * @param string $postcode NL postcode to validate - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if postcode is ok, false otherwise */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/ptBR.php?r1=1.2&r2=1.3&ty=u Index: pear/Validate/Validate/ptBR.php diff -u pear/Validate/Validate/ptBR.php:1.2 pear/Validate/Validate/ptBR.php:1.3 --- pear/Validate/Validate/ptBR.php:1.2 Tue Feb 3 18:34:53 2004 +++ pear/Validate/Validate/ptBR.php Wed Dec 15 07:58:00 2004 @@ -16,7 +16,7 @@ // | Authors: Silvano Girardi Jr. <silvano@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ptBR.php,v 1.2 2004/02/03 23:34:53 neufeind Exp $ +// $Id: ptBR.php,v 1.3 2004/12/15 12:58:00 dufuz Exp $ // Specific validation methods for data used in pt_BR // @@ -27,28 +27,13 @@ * and other languages) * format: xxxxx-xxx * - * @param string $cep pt_BR CEP to validate + * @param string $postalCode pt_BR CEP/postalCode to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool true if $cep is ok, false otherwise */ - function cep($cep) + function postalCode($postalCode, $strong = false) { - return (ereg('(^[0-9]{5})-([0-9]{3})$', $cep)); - } - - /** - * validates a postcode; alias-function - * - * @access public - * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) - * @return bool - */ - function postcode($postcode, $strong=false) - { - // $strong is not used here at the moment; added for API compatibility - // checks might be added at a later stage - - return cep($postcode); + return (ereg('(^[0-9]{5})-([0-9]{3})$', $postalCode)); } /** http://cvs.php.net/diff.php/pear/Validate/Validate/UK.php?r1=1.13&r2=1.14&ty=u Index: pear/Validate/Validate/UK.php diff -u pear/Validate/Validate/UK.php:1.13 pear/Validate/Validate/UK.php:1.14 --- pear/Validate/Validate/UK.php:1.13 Mon Nov 8 19:40:59 2004 +++ pear/Validate/Validate/UK.php Wed Dec 15 07:58:00 2004 @@ -17,7 +17,7 @@ // | Stefan Neufeind <pear.neufeind@speedpartner.de> | // +----------------------------------------------------------------------+ // -// $Id: UK.php,v 1.13 2004/11/09 00:40:59 dufuz Exp $ +// $Id: UK.php,v 1.14 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in UK @@ -26,7 +26,8 @@ class Validate_UK { // overlay function - function getZipValFunc() { + function getZipValFunc() + { return 'postcode'; } @@ -44,10 +45,10 @@ * * @access public * @param string the postcode to be validated - * @param bool optional; strong checks (e.g. against a list of postcodes) + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) * @return bool */ - function postcode($postcode, $strong = false) + function postalCode($postcode, $strong = false) { // $strong is not used here at the moment; added for API compatibility // checks might be added at a later stage http://cvs.php.net/diff.php/pear/Validate/Validate/US.php?r1=1.13&r2=1.14&ty=u Index: pear/Validate/Validate/US.php diff -u pear/Validate/Validate/US.php:1.13 pear/Validate/Validate/US.php:1.14 --- pear/Validate/Validate/US.php:1.13 Mon Nov 8 04:17:49 2004 +++ pear/Validate/Validate/US.php Wed Dec 15 07:58:00 2004 @@ -17,7 +17,7 @@ // | Tim Gallagher <timg@sunflowerroad.com> | // +----------------------------------------------------------------------+ // -// $Id: US.php,v 1.13 2004/11/08 09:17:49 dufuz Exp $ +// $Id: US.php,v 1.14 2004/12/15 12:58:00 dufuz Exp $ // // Specific validation methods for data used in the United States // @@ -170,5 +170,86 @@ } return $high_groups; } + + /** + * Validates a US Postal Code format (ZIP code) + * + * @param string $postalCode the ZIP code to validate + * @param bool optional; strong checks (e.g. against a list of postcodes) (not implanted) + * @return boolean TRUE if code is valid, FALSE otherwise + * @access public + * @static + * @todo Integrate with USPS web API + */ + function postalCode($postalCode, $strong = false) + { + return (bool) preg_match('/^[0-9]{5}(-[0-9]{4})?$/', $postalCode); + } + + /** + * Validates a "region" (i.e. state) code + * + * @param string $region 2-letter state code + * @return bool Whether the code is a valid state + * @static + */ + function region($region) + { + switch (strtoupper($region)) { + case 'AL': + case 'AK': + case 'AZ': + case 'AR': + case 'CA': + case 'CO': + case 'CT': + case 'DE': + case 'DC': + case 'FL': + case 'GA': + case 'HI': + case 'ID': + case 'IL': + case 'IN': + case 'IA': + case 'KS': + case 'KY': + case 'LA': + case 'ME': + case 'MD': + case 'MA': + case 'MI': + case 'MN': + case 'MS': + case 'MO': + case 'MT': + case 'NE': + case 'NV': + case 'NH': + case 'NJ': + case 'NM': + case 'NY': + case 'NC': + case 'ND': + case 'OH': + case 'OK': + case 'OR': + case 'PA': + case 'RI': + case 'SC': + case 'SD': + case 'TN': + case 'TX': + case 'UT': + case 'VT': + case 'VA': + case 'WA': + case 'WV': + case 'WI': + case 'WY': + return true; + } + return false; + } } ?>