Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding Portuguese Validation class.

Adding Portuguese postal validation.
  • Loading branch information...
commit 92ace25b06e3eaa3ec89e4a1dc73581f88d6a8d4 1 parent 8131392
@predominant predominant authored
Showing with 88 additions and 0 deletions.
  1. +41 −0 libs/pt_validation.php
  2. +47 −0 tests/cases/libs/pt_validation.test.php
View
41 libs/pt_validation.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Portuguese Localized Validation class. Handles localized validation for Spain
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package localized
+ * @subpackage localized.libs
+ * @since Localized Plugin v 0.1
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+/**
+ * PtValidation
+ *
+ * @package localized
+ * @subpackage localized.libs
+ */
+class PtValidation {
+
+/**
+ * Checks Postal Codes for Portugal
+ *
+ * @param string $check The value to check.
+ * @return boolean
+ * @access public
+ */
+ function postal($check) {
+ $pattern = '/^[1-9]{1}[0-9]{3}-[0-9]{3}$/';
+ return preg_match($pattern, $check);
+ }
+}
+?>
View
47 tests/cases/libs/pt_validation.test.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Portuguese Localized Validation class test case
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package localized
+ * @subpackage localized.tests.cases.libs
+ * @since Localized Plugin v 0.1
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+App::import('Lib', 'Localized.PtValidation');
+
+/**
+ * PtValidationTestCase
+ *
+ * @package localization
+ * @subpackage localized.tests.cases.libs
+ */
+class PtValidationTestCase extends CakeTestCase {
+
+/**
+ * test the postal method of PtValidation
+ *
+ * @return void
+ * @access public
+ */
+ function testPostal() {
+ $this->assertFalse(PtValidation::postal('111'));
+ $this->assertFalse(PtValidation::postal('1111'));
+ $this->assertFalse(PtValidation::postal('130896'));
+ $this->assertFalse(PtValidation::postal('13089-33333'));
+ $this->assertFalse(PtValidation::postal('1000 333'));
+ $this->assertFalse(PtValidation::postal('0000 333'));
+ $this->assertFalse(PtValidation::postal('13A89-4333'));
+ $this->assertTrue(PtValidation::postal('1389-333'));
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.