Category Archives: Programming

Stuff about stringing ones and zeroes together to form something useful. Contains some elaborations of the answers I post on Stack Overflow

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

Obfuscating mailto and tel links

When I designed my programmer’s portfolio site one of the things I noted it needs was my contact information. One alternative to doing that is a contact form, which has the advantage of avoiding spam from being sent to your e-mail address. However, I also found it very unnatural compared to having it open the user’s e-mail client or phone client. The mailto: and tel: links are the standard practice for contact information links, but it has the flaw of spam bots extracting the information and storing it for robocalls in the future.

So I get around it by obfuscating the links and text so that these bots would have a slightly harder time of getting the data.
Continue reading Obfuscating mailto and tel links