Skip to content

Commit

Permalink
Merge pull request #97 from cakephp/more-postal
Browse files Browse the repository at this point in the history
Add postal validation for Croatia.
  • Loading branch information
lorenzo committed May 19, 2015
2 parents d0bbc3c + 3d809de commit 8d3fbdb
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ You can also access the localized validators any time you would call `Validation
}
```

## Po files
## PO files

This plugin also houses translations for the client-facing translated strings in the core (the cake domain). to use these files link or copy them
into their expected location: `APP/locale/<locale>/LC_MESSAGES/cake.po`
This plugin also houses translations for the client-facing translated strings in the core (the `cake` domain). to use these files link or copy them
into their expected location: `APP/Locale/<locale>/LC_MESSAGES/cake.po`

## LC_TIME files

This plugin also houses POSIX compliant LC_TIME files which are used for translating
time related string of LC_TIME domain. To use these files link or copy them into
their expected location: `APP/locale/<locale>/LC_TIME`.
their expected location: `APP/Locale/<locale>/LC_TIME`.

## Migration Guide

Expand Down
32 changes: 32 additions & 0 deletions Test/Case/Validation/HrValidationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Slovak Localized Validation class test case
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('HrValidation', 'Localized.Validation');

/**
* HrValidationTest
*
*/
class HrValidationTest extends CakeTestCase {

/**
* test the postal method of HrValidation
*
* @return void
*/
public function testPostal() {
$this->assertTrue(HrValidation::postal('25616'));
$this->assertFalse(HrValidation::postal('0989'));
}
}
42 changes: 42 additions & 0 deletions Test/Case/Validation/IdValidatationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Indonesian Localized Validation class test case
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('IdValidation', 'Localized.Validation');

/**
* Indonesian Validation Test Case
*/
class IdValidationTest extends CakeTestCase {

/**
* Test the mobile method of IdValidation
*
* @return void
*/
public function testMobile() {
$this->assertTrue(IdValidation::mobile('08125985608'));
$this->assertFalse(IdValidation::mobile('8125985608'));
}

/**
* Test the postal method of IdValidation
*
* @return void
*/
public function testPostal() {
$this->assertTrue(IdValidation::postal('15000'));
$this->assertFalse(IdValidation::postal('00091'));
}

}
24 changes: 12 additions & 12 deletions Test/Case/Validation/RsValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class RsValidationTest extends CakeTestCase {
*
* @return void
*/
public function testJMBG() {
$this->assertTrue(RsValidation::jmbg('1707017170007'));
$this->assertFalse(RsValidation::jmbg('1707017170008'));
$this->assertFalse(RsValidation::jmbg('170701717000'));
$this->assertFalse(RsValidation::jmbg('A707017170007'));
public function testPersonId() {
$this->assertTrue(RsValidation::personId('1707017170007'));
$this->assertFalse(RsValidation::personId('1707017170008'));
$this->assertFalse(RsValidation::personId('170701717000'));
$this->assertFalse(RsValidation::personId('A707017170007'));
}

/**
* test the postal_number method of RsValidation
*
* @return void
*/
public function testPostalNumber() {
$this->assertTrue(RsValidation::postal_number('11090'));
$this->assertFalse(RsValidation::postal_number('111000'));
$this->assertFalse(RsValidation::postal_number('A1100'));
public function testPostal() {
$this->assertTrue(RsValidation::postal('11090'));
$this->assertFalse(RsValidation::postal('111000'));
$this->assertFalse(RsValidation::postal('A1100'));
}

/**
Expand All @@ -50,8 +50,8 @@ public function testPostalNumber() {
* @return void
*/
public function testAddressCode() {
$this->assertTrue(RsValidation::address_code('122407'));
$this->assertFalse(RsValidation::address_code('11090'));
$this->assertFalse(RsValidation::address_code('A11090'));
$this->assertTrue(RsValidation::addressCode('122407'));
$this->assertFalse(RsValidation::addressCode('11090'));
$this->assertFalse(RsValidation::addressCode('A11090'));
}
}
56 changes: 56 additions & 0 deletions Validation/HrValidation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Localized Validation class. Handles localized validation for Croatia.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('LocalizedValidation', 'Localized.Validation');

/**
* HrValidation
*
*/
class HrValidation extends LocalizedValidation {

/**
* Checks a postal code for Croatia.
*
* @param string $check The value to check.
* @return bool Success.
*/
public static function postal($check) {
$pattern = '/^\d{5}$/';
return (bool)preg_match($pattern, $check);
}

/**
* Checks a phone number.
*
* @param string $check The value to check.
* @return bool Success.
* @throws NotImplementedException
*/
public static function phone($check) {
throw new NotImplementedException('Validation method not implemented yet.');
}

/**
* Checks a country specific identification number.
*
* @param string $check The value to check.
* @return bool Success.
* @throws NotImplementedException
*/
public static function personId($check) {
throw new NotImplementedException('Validation method not implemented yet.');
}

}
4 changes: 2 additions & 2 deletions Validation/IdValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IdValidation extends LocalizedValidation {
*/
public static function postal($check) {
$pattern = '/[1-9][0-9]{4}/';
return preg_match($pattern, $check);
return (bool)preg_match($pattern, $check);
}

/**
Expand All @@ -40,7 +40,7 @@ public static function postal($check) {
*/
public static function mobile($check) {
$pattern = '/(^0|^62|\+62)(8[0-9]{8,10})$/';
return preg_match($pattern, $check);
return (bool)preg_match($pattern, $check);
}

/**
Expand Down

0 comments on commit 8d3fbdb

Please sign in to comment.