twitter/twitter-cldr-rb

Not working for the Canada 3 digits postal code

Closed this issue · 7 comments

I am using this gem in my application to validate the postal codes
like this
postal_code = TwitterCldr::Shared::PostalCodes.for_territory('ca')
errors.add(:zipcode, :invalid) if !postal_code.valid?('T2P') # false

but this is not working for the postal code of Canada with 3 alphabets

Hey @GopalChavan, forgive my ignorance, but aren't Canadian postal codes always 6 letters long? From the Wikipedia article:

A Canadian postal code is a six-character string that forms part of a postal address in Canada. Like British, Irish and Dutch postcodes, Canada's postal codes are alphanumeric. They are in the format A1A 1A1, where A is a letter and 1 is a digit, with a space separating the third and fourth characters.

I tried to search for T2P on Canada Post's website without any luck. What am I missing here?

Thanks for the quick reply @camertron
so, I just searched in google with "canada alberta postal code" and it gave results with list of postalcodes where there are also postal codes with 3 letters like

  • T2P
  • T2E
  • T3R etc

Hey @GopalChavan, if you click on any of those three-letter postal codes that come up in the Google search, you'll see that they correspond to an entire region or neighborhood, not a specific home or business.

What's your use-case? Are you validating partial postal codes or whole neighborhoods?

In our application its the shipping address of the customer

Ok, so your Canadian customers are actually entering 3-digit postal codes?

As of now, the application is not in production, just we are testing the Canadian postal codes. What would be the valid postal code for Canada? Is that 6 digits only or it may 3 digits.

I believe all Canadian postal codes are supposed to be six digits, or more specifically, three digits, a space, then another three digits. For example, this is the address for one of the Bank of Montréal branches:

630, boulevard René-Lévesque Ouest, Montreal, QC H3B 1S6

Notice the H3B 1S6 postal code.