To add Canadian Specific Postal Code validation. TO: find solution that does not touch vanilla code.
find all files that solicit postal code. These include:
vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/persistent/checkout/onepage/billing.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/customer/address/edit.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/checkout/onepage/shipping.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/persistent/customer/form/register.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/persistent/checkout/onepage/billing.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/opc/customer/form/register.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/opc/onepage/shipping.phtml vi /var/www/shop/app/design/frontend/sm-fcstore/default/template/opc/onepage/billing.phtml
add new class called "validate-zip-code-canadian". You can safely remove class called "validate-zip-international"
<div class="input-box"> <input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" name="billing[postcode]" id="billing:postcode" value=" <?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-code-canadian validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" /> </div>
/var/www/shop/js/prototype/validation.js
add to end of file:
Validation.addAllThese([ ['validate-zip-code-canadian', 'Canadian postal format is A9A 9A9.', function(v) { return Validation.get('IsEmpty').test(v.trim()) || /(^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$)/.test(v.trim()); }] ])
If you use multiple languages, add translation string into Mage_Core.csv and jstranslator.xml
vi /var/www/shop/app/code/core/Mage/Core/etc/jstranslator.xml
<validate-zip-code-canadian translate="message" module="core"> <message>Canadian postal format is A9A 9A9.</message> </validate-zip-code-canadian>
vi /var/www/shop/app/locale/fr_FR/Mage_Core.csv
"Canadian postal format is A9A 9A9.","Le format postal canadien est A9A 9A9."