Christopher Short Posted February 10, 2022 Share Posted February 10, 2022 What needs to be done to fix zip codes? The US is 5 digit or 5+4. USPS will not recognize 9 digits and provide a quote. If a customer enters the 5+4 without a -, it should auto format to xxxxx-xxxx from xxxxxxxxx Link to comment Share on other sites More sharing options...
bsmither Posted February 10, 2022 Share Posted February 10, 2022 Looking at the USPS module's shipping.class.php file, near lines 107: if(preg_match('/^([0-9]){5}-([0-9]){4}$/',$delivery['postcode'])) { $delivery['postcode'] = substr($delivery['postcode'],0,5); } If the string has a dash between the 5 and 4 count numbers, then use only the first 5 numbers. We can try to modify this as follows: From: '/^([0-9]){5}-([0-9]){4}$/' To: '/^([0-9]){5}-?([0-9]){4}$/' By putting a question mark after the dash, the test becomes "..., followed by a dash that may or may not be there,...". However, suppose the customer uses a space instead of a dash? One would think a US resident would know to use a dash and nothing but a single dash, if wanting to include the extension. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.