diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index 229089337110a..e3eb72f19c222 100644 --- a/app/code/Magento/Directory/etc/zip_codes.xml +++ b/app/code/Magento/Directory/etc/zip_codes.xml @@ -81,6 +81,7 @@ ^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}\s[0-9]{1}[a-zA-z]{1}[0-9]{1}$ + ^[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}[a-zA-z]{1}[0-9]{1}$ diff --git a/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php b/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php index cdc26079c4d36..2963c3e4f91c7 100644 --- a/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Directory/Model/Country/Postcode/ValidatorTest.php @@ -42,6 +42,24 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist() $this->validator->validate('12345', 'INVALID-CODE'); } + public function testInvalidCanadaZipCode() { + $resultOnlyDigits = $this->validator->validate('12345', 'CA'); + $resultMoreCharactersThanNeeded = $this->validator->validate('A1B2C3D', 'CA'); + $resultLessCharactersThanNeeded = $this->validator->validate('A1B2C', 'CA'); + $resultMoreThanOneSpace = $this->validator->validate('A1B 2C3', 'CA'); + $this->assertFalse($resultOnlyDigits); + $this->assertFalse($resultMoreCharactersThanNeeded); + $this->assertFalse($resultLessCharactersThanNeeded); + $this->assertFalse($resultMoreThanOneSpace); + } + + public function testValidCanadaZipCode() { + $resultPattern1 = $this->validator->validate('A1B2C3', 'CA'); + $resultPattern2 = $this->validator->validate('A1B 2C3', 'CA'); + $this->assertTrue($resultPattern1); + $this->assertTrue($resultPattern2); + } + /** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength)