Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for bug #17850

git-svn-id: http://svn.php.net/repository/pear/packages/Validate/trunk@308697 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 47d310e837fbb837919b462b40d7b6f16367488b 1 parent 2d9798e
@kenguest kenguest authored
Showing with 19 additions and 6 deletions.
  1. +15 −6 Validate/AR.php
  2. +4 −0 tests/validate_AR_postal_code.phpt
View
21 Validate/AR.php
@@ -29,7 +29,7 @@
* This class provides methods to validate:
* - Postal code CPA (Código Postal Argentino)
* - Regions - provinces of Argentina
- *
+ *
* @category Validate
* @package Validate_AR
* @author Marcelo Santos Araujo <msaraujo@php.net>
@@ -48,8 +48,8 @@ class Validate_AR
*
* @param string $postalCode AR CPA/postalCode to validate
* @param bool $strong optional; checks (e.g. against a list of postcodes)
- * (not implemented)
- * @param bool $casesens optional; (true - case sensitive, false - not case
+ * (not implemented)
+ * @param bool $casesens optional; (true - case sensitive, false - not case
* sensitive)
*
* @return bool true if CPA is ok, false otherwise
@@ -59,10 +59,19 @@ class Validate_AR
*/
function postalCode($postalCode, $strong = false, $casesens = true)
{
- $regexp = $casesens ? '/^[B-T]\d{4}[A-Z]{3}$/' : '/^[B-T]\d{4}[A-Z]{3}$/i';
- return (bool)preg_match($regexp, $postalCode);
+ if (strlen($postalCode) == 8) {
+ $regexp = $casesens ? '/^[B-T]\d{4}[A-Z]{3}$/' : '/^[B-T]\d{4}[A-Z]{3}$/i';
+ return (bool) preg_match($regexp, $postalCode);
+ } elseif (strlen($postalCode) == 5) {
+ $regexp = $casesens ? '/^[B-T]\d{4}$/' : '/^[B-T]\d{4}$/i';
+ return (bool) preg_match($regexp, $postalCode);
+ } elseif (strlen($postalCode) == 4) {
+ return (bool) preg_match('/^\d{4}$/', $postalCode);
+ } else {
+ return false;
+ }
}
-
+
/**
* Validates a "region" (i.e. province) code
*
View
4 tests/validate_AR_postal_code.phpt
@@ -23,6 +23,8 @@ $codes = array(
'U123AB', //NOK
'U1234ABCD', //NOK
'b1234abc', //NOK
+'1234', //OK
+'B1234'//OK
);
echo "\nTest Postal Codes\n";
foreach ($codes as $code) {
@@ -43,3 +45,5 @@ U1234ABC: NO
U123AB: NO
U1234ABCD: NO
b1234abc: NO
+1234: YES
+B1234: YES
Please sign in to comment.
Something went wrong with that request. Please try again.