Skip to content

Postal Code (Canada)

Omar Shammas edited this page Sep 13, 2013 · 1 revision

Formats the postal code in the A1A 1A1 format:

  • Limits to 6 letters and numbers
  • Restricts to alphanumeric (letters and numbers)

According to http://stackoverflow.com/questions/1146202/canada-postal-code-validation.

  • First letter can't be D,I,O,Q,U,W,Z
  • Second letter can't be D,I,O,Q,U
  • Third letter can't be D,I,O,Q,U
$('input.postal_code').formance('format_postal_code');

Validates a postal code field:

  • Does NOT validate whether it is an actual postal code, check with Canada Post if you want to be certain.
  • Validates length (after stripping away non alphanumeric characters)
  • Validates alternating letters and numbers
  • First letter can't be D,I,O,Q,U,W,Z
  • Second letter can't be D,I,O,Q,U
  • Third letter can't be D,I,O,Q,U
$("<input value='a1a1a1' />").formance('validate_postal_code');     // true
$("<input value='A1A 1A1' />").formance('validate_postal_code');   // true
$("<input value='a1a1' />").formance('validate_postal_code');        // false