Permalink
Browse files

v1.0.3 of Validate_IE

  • Loading branch information...
1 parent c454558 commit 35a918ba97f04f8bc9000677c2a72efcb5fb7365 @kenguest kenguest committed Jan 1, 2013
Showing with 39 additions and 8 deletions.
  1. +13 −3 Validate/IE.php
  2. +19 −4 package_IE.xml
  3. +7 −1 tests/validate_IE_licensePlate.phpt
View
16 Validate/IE.php
@@ -333,15 +333,25 @@ function licensePlate($number)
{
//in_array is case sensitive, so use strtoupper...
$plate = strtoupper($number);
- $regex = "/^\d{2}[\ -]([A-Z][A-Z]?)[\ -]\d{1,6}$/";
+ $regex = "/^(\d{2,3})[\ -]([A-Z][A-Z]?)[\ -]\d{1,6}$/";
if (preg_match($regex, $plate, $matches)) {
- $mark = strtoupper($matches[1]);
+ $mark = strtoupper($matches[2]);
//check valid index mark
$marks = array('C','CE','CN','CW','D','DL','G','KE','KK','KY','L',
'LD','LH','LK','LM','LS','MH','MN','MO','OY','RN',
'SO','TN','TS','W','WD','WH','WX','WW');
- return in_array($mark, $marks);
+ if (in_array($mark, $marks)) {
+ // The first component, if 3 digits in length can only end
+ // with a '1' or a '2'.
+ if (strlen($matches[1]) == 3) {
+ $end = (int) substr($matches[1], 2, 1);
+ return ($end == 1) || ($end == 2);
+ }
+ return true;
+ } else {
+ return false;
+ }
} else {
//two pre-1987 codes are still in use. ZZ and ZV.
//format is ZZ nnnnn - 5 digits for ZZ code and as few as 4 for ZV
View
23 package_IE.xml
@@ -25,10 +25,10 @@
<email>ken@linux.ie</email>
<active>yes</active>
</lead>
- <date>2008-11-20</date>
- <time>21:04:00</time>
+ <date>2013-01-01</date>
+ <time>02:04:00</time>
<version>
- <release>1.0.2</release>
+ <release>1.0.3</release>
<api>1.0.0</api>
</version>
<stability>
@@ -37,7 +37,7 @@
</stability>
<license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
<notes>
-* bug fix: #15097 - package not marked as depending on validate_finance
+* Validate the first component of license plates that consist of three digits.
</notes>
<contents>
<dir name="/">
@@ -76,6 +76,21 @@
<changelog>
<release>
<version>
+ <release>1.0.3</release>
+ <api>1.0.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2013-01-01</date>
+ <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
+ <notes>
+* Validate the first component of license plates that consist of three digits.
+ </notes>
+ </release>
+ <release>
+ <version>
<release>1.0.2</release>
<api>1.0.0</api>
</version>
View
8 tests/validate_IE_licensePlate.phpt
@@ -22,7 +22,10 @@ $plates = array(
'98-KY-2655', //OK
'06-D-2600', //OK
'06-DE-2600', //NOK - DE index doesn't exist
-'07=KY=23233' //NOK - wrong delimiters
+'07=KY=23233', //NOK - wrong delimiters
+'131-KY-23233', //OK
+'132-KY-23233', //OK
+'133-KY-23233', //NOK - first component with 3 digits may only end with a 1 or a 2.
);
echo "\nTest License Plates\n";
foreach ($plates as $plate) {
@@ -47,4 +50,7 @@ ZV-7654321: NO
06-D-2600: YES
06-DE-2600: NO
07=KY=23233: NO
+131-KY-23233: YES
+132-KY-23233: YES
+133-KY-23233: NO

0 comments on commit 35a918b

Please sign in to comment.