-
- Frikki

-
Total Posts: 20
Joined: 2007-09-25
Reykjavík, Iceland
|
This is rather ridiculous, as the zip code validation should change according to country selection, but instead is a hard-coded regexp that only seems to accommodate US zip codes. Say, you have a store that ships to 4 different countries, i.e. Iceland, Denmark, Sweden and Norway, then you need to have checks for Iceland, which is 3 digits and never starting with a zero. Denmark would be a 4 digit check, also not beginning with a zero. Sweden have 5 digits in their postal codes, but have a space following the first 3 digits, like this for example 100 12.
It seems rather daunting task to try to accomplish a fix, wherefore the solution would be to simply bypass the JavaScript validation. If you despite the tedious work feel like making the checks, the script provides a mechanism for constructing the different checks in an array. In each array item you could include a check for the value selected in the country field. Note that the country_id uses short country codes, like DK for Denmark etc.
I put together a simple example that illustrates the concept:
<script type="text/javascript"> var coShippingMethodForm = new VarienForm('shipping-zip-form'); Validation.addAllThese( [ ['validate-postcode', '<?php echo $this->__('Please enter a valid zip code. For example 90602 or 90602-1234.') ?>', function(v) { var country_id = 'IS' var country = $('country'); var element = $('postcode'); if (element && ('' != element.value) && (country_id == country.value)) { if (!element.value.match(/(^[1-9]{1}[0-9]{2}$)/ )) { return false; } } return true; }], ['validate-postcode', '<?php echo $this->__('Please enter a valid zip code. For example 90602 or 90602-1234.') ?>', function(v) { var country_id = 'DK' var country = $('country'); var element = $('postcode'); if (element && ('' != element.value) && (country_id == country.value)) { if (!element.value.match(/(^[1-9]{1}[0-9]{3}$)/ )) { return false; } } return true; }] ] ); </script>
The first array item checks for Icelandic postal codes (3 digits) and the second checks for Danish postal codes (4 digits). Note that you would also have to construct separate warning messages.
The script could be optimized for checking regexp on multiple countries at once that uses same pattern postal codes, but that might come later.
The file you need to edit is template/checkout/cart in your frontend interface at around line 92 (Modern Theme v.1.1.6).
|