I need to format the Canadian zip code correctly if it is entered incorrectly.
Format: ### ### where "#" can be a number or a letter, for example: M5R 2G3
I tried this: (its broken for testing)
shipping.zip = shipping.zip.toUpperCase().split('') shipping.zip = shipping.zip.splice(3, 0, ' ') shipping.zip = shipping.zip.join().replace(/,/g, '');
But when I enter:
m5r2g3
I get the following:
['M', '5', 'R', '2', 'G', '3']
[]
And here it is. I have no idea why it is not working. Please help. Thanks.
source share