Permalink
Browse files

Bug #18287 0800 numbers not supported

git-svn-id: http://svn.php.net/repository/pear/packages/Validate/trunk@308553 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 13d55b9 commit ee174d7c6311f5b601b0f3ab01d0bbbb9882a394 @CloCkWeRX CloCkWeRX committed Feb 22, 2011
Showing with 29 additions and 7 deletions.
  1. +12 −6 Validate/NZ.php
  2. +17 −1 tests/Validate_NZ.phpt
View
@@ -54,7 +54,7 @@ class Validate_NZ
* Validate New Zealand postal codes
*
* @param string $postcode postcode to validate
- * @param bool $strong optional; strong checks against a list of
+ * @param bool $strong optional; strong checks against a list of
* postcodes
*
* @static array $postcodes
@@ -161,6 +161,7 @@ function region($region)
* @param string $number the number to validate
* @param bool $requireAreaCode Optional (default: true)
*
+ * @see http://en.wikipedia.org/wiki/Telephone_numbers_in_New_Zealand
* @access public
* @static array $servicePrefix, $mobilePrefix
* @return bool The valid or invalid phone number
@@ -198,6 +199,11 @@ function phoneNumber($number, $requireAreaCode = true)
}
break;
case 11:
+ if (substr($number, 0, 4) == '0800') {
+ // Is 0800 with 7 digits?
+ $regexp = "(^0800[0-9]{7}$)";
+ }
+
if (substr($number, 0, 3) == "640") {
// Is land line with country code
$regexp = "(^640(3|4|6|7|9)[0-9]{7})";
@@ -252,13 +258,13 @@ function carReg($reg)
/**
* Return true if the checksum[s] in the specified value is valid as
* regards the value being a valid IRD number.
- *
+ *
* @param string $ssn Value to perform the validation on
*
* @access public
* @return boolean
*/
- function checkIRD($ssn)
+ function checkIRD($ssn)
{
$ird = (int) str_replace("-", "", $ssn);
if (strlen("$ird") == 8 ) {
@@ -274,8 +280,8 @@ function checkIRD($ssn)
}
$remainder = ($sum%11);
$checkdigit = 11 - $remainder;
- if ($sird[7] == $checkdigit) {
- return true;
+ if ($sird[7] == $checkdigit) {
+ return true;
}
if ($checkdigit == 10) {
$weights = array(4,3,2,5,2,7,6);
@@ -290,7 +296,7 @@ function checkIRD($ssn)
}
return ($sird[7] == $checkdigit);
}
- }
+ }
return false;
}
}
@@ -101,7 +101,16 @@ $phoneNumbers = array(
"0500 123123", //NOk
"0808 505050", //NOk
- "0908123456"); //NOk
+ "0908123456", //NOk
+
+ "0800 269 296", //Ok
+ "0800 803 804", //Ok
+ "0800 275 269", //Ok
+ "0800 11 33 55", //Ok
+ "0800 400 600", //Ok
+ "0800 269 4663", //Ok
+ "0800 306 3010" //Ok
+ );
$regions = array(
"AUK", //Ok
@@ -228,6 +237,13 @@ O1lO: NO
0500 123123: NO
0808 505050: NO
0908123456: NO
+0800 269 296: YES
+0800 803 804: YES
+0800 275 269: YES
+0800 11 33 55: YES
+0800 400 600: YES
+0800 269 4663: YES
+0800 306 3010: YES
----Test region----
AUK: YES
WTC: YES

0 comments on commit ee174d7

Please sign in to comment.