All posts by Archimedes Trajano

Canadian SIN Bean Validation plus Generation

There are many algorithms that generate and validate Canadian SIN numbers. This is the one I use with bean validation. Unlike most other implementations I took into consideration that 8 is not used as the first character in a Canadian SIN. In addition, I utilized a map to deal with the doubled number for the even digits rather than doing the calculation and dealing with greater than 10 results. No regexes are involved either.
Continue reading Canadian SIN Bean Validation plus Generation

Canadian Postal Code Validation

StatsCan has posted the rules for what is a valid Canadian postal code:

The postal code is a six-character code defined and maintained by Canada Post Corporation (CPC) for the purpose of sorting and delivering mail. The characters are arranged in the form ‘ANA NAN’, where ‘A’ represents an alphabetic character and ‘N’ represents a numeric character (e.g., K1A 0T6). The postal code uses 18 alphabetic characters and 10 numeric characters. Postal codes do not include the letters D, F, I, O, Q or U, and the first position also does not make use of the letters W or Z.

This post shows how I do the validation using two regular expressions… a strict one and a permissive one combined with Java Bean Validation.
Continue reading Canadian Postal Code Validation