Skip to content

Commit

Permalink
RoValidation - postal
Browse files Browse the repository at this point in the history
  • Loading branch information
cornel-b committed Feb 2, 2014
1 parent 99114b9 commit 2a0ee72
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Test/Case/Validation/RoValidationTest.php
@@ -0,0 +1,39 @@
<?php
/**
* RO Localized Validation class test case
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package Localized.Test.Case.Validation
* @since Localized Plugin v 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('RoValidation', 'Localized.Validation');

/**
* RoValidationTest
*
* @package Localized.Test.Case.Validation
*/
class RoValidationTest extends CakeTestCase {

/**
* test the postal method of RoValidation
*
* @return void
*/
public function testPostal() {
$this->assertTrue(RoValidation::postal('517006'));
$this->assertFalse(RoValidation::postal('23708'));
$this->assertFalse(RoValidation::postal('23 708'));
}

}
38 changes: 38 additions & 0 deletions Validation/RoValidation.php
@@ -0,0 +1,38 @@
<?php
/**
* RO Localized Validation class. Handles localized validation for Romania
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package Localized.Validation
* @since Localized Plugin v 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

/**
* RoValidation
*
* @package Localized.Validation
*/
class RoValidation {

/**
* Checks postal codes for Romania
*
* @param string $check The value to check.
* @return boolean
*/
public static function postal($check) {
$pattern = '/^[0-9]{6}$/';
return (bool)preg_match($pattern, $check);
}

}

0 comments on commit 2a0ee72

Please sign in to comment.