Jump to content

Zip COde


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...