Jump to content

Zip COde


Christopher Short

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...