The application I am currently assigned to is for use by automotive dealers to sell their vehicles and is marketed to both the US and Canadian dealers. As a result of this, taxes and their various identifying codes and numbers come into play. Recently we had to do some tweaking to the GST/HST and QST fields and I did some digging into the format of these.
Anyways, here is my quick guide to verifying Canadian GST/HST and QST numbers.

GST/HST

All companies that deal with Revenue Canada are issued a BN (Business Number). To understand the GST/HST number, you need to understand the BN.

The BN has 15 digits long, which is broken into 3 parts.

  • Positions 1 – 9 are numeric and identify the business
  • Positions 10 – 11 are one of the following codes
    • RC – corporate income tax
    • RM – import / export
    • RP – payroll deductions
    • RT – GST/HST
  • Positions 12 – 16 are the reference number

Using the above couples with FAQ 4 on the GST/HST Registry FAQ) a valid GST number would be 12345 6789 RT0001.

Just because it would be too easy to write a regex to verify that, the placement of spaces appears to be pretty much arbitrary. The above is the format listed in what I am using as my authoritative source, The Business Number and Your Canada Revenue Agency Accounts but you can see it in a number of different formats with even the quickest search.

  • 123456789 RT0001
  • 12345 6789 RT 0001
  • 123456789 RT 0001
  • etc

I suspect that Revenue just mashes the parts together and pulls out the relevant parts anyways but it means you have to be careful constructing the regex.

Another hiccup is when Quebec issues the number as it may or may not have the reference number. See Operating in Quebec for more details.

QST

Similar to the GST/HST number, there is a defined format for the QST number. It would be of course too simple to use the same number in Quebec, but that politics for you. The QST number is 16 characters long and has the following parts

  • Positions 1 – 10 are numeric and is the company’s NEQ (Quebec Enterprise Number)
  • Positions 11 and 12 are TQ
  • Positions 13 – 16 are numeric

I got this format from the QST Verification page.

The NEQ portion has another validation component. The first 2 digits represent the company’s legal form as per The Enterprise Register and Its Contents.

  • 11XXXXXXXX: Legal person
  • 22XXXXXXXX: Sole proprietorship
  • 33XXXXXXXX: Partnership, association or other group

Even though it shares a similar format to the GST number, it appears that the standard way of displaying it is 1134567890 TQ 0001 as the overwhelming majority of pages listed it this way. My guess would be that assuming this would be dangerous in a regex though.