Checking the Canadian Postcode Format

The question that triggered this entry was: How to go to the next field as soon as the canadian postcode is entered. As always there is more than one solution. I describe here what I think is the best one.

Use this Custom Function in a Script

The original task was to go to a different field, once the postcode has been entered correctly. so we need a script:

# We need a regular field to enter the postcode, for example
# to::postcode
# That field must have an onModifyElement event, calling our script
Enter Postcode
Set Variable [$p ; CanadianZip ( to::postcode )]
If ( not isempty ( $p )
# replace entry with formatted postcode
to::postcode = $p
Go to Field [ to::next ]
Else
# indicate the postcode is not OK somehow
End if

Any comments are welcome

Examples are provided "AS IS" without warranties of any kind. Use at your own risk.