Summary

This article provides examples of how the Validation and Verification Rules may be applied.

There are three scenarios:

  • Scenario 1: Mandatory entry.
  • Scenario 2: Optional entry.
  • Scenario 3: Prohibited entry.

 Examples

In order to illustrate the application of Validation and Verification Rules, I will use three fields:

  • The Canadian Social Insurance Number, which will be assumed to be a text field into which a user makes an entry.
    • There is a validation calculation to determine if the entry is acceptable. The calculation uses the Luhn algorithm, which uses the digits in the field to ensure that the check digit is correct. If the check digit is correct, then the entry is valid.
    • The entry for a Social Insurance Number is mandatory in some circumstance, optional in other circumstances, and prohibited in still other circumstances.
  • A checkbox field. By selecting this field, the indication is that a Social Insurance Number has been applied for. I refer to this as the "Applied For" field.
    • If the field is selected, then an entry must be provided for the date on which the Social Insurance Number was applied for. I refer to this as the "Applied For Date" field.

 Scenario 1: Mandatory entry

Validation rules

Social Insurance Number field:

  • If an entry is made in this field, the entry must consist of exactly nine or eleven characters:
    • If nine characters, then all characters must be digits.
    • If eleven characters, then there must have exactly nine digits, with either a dash or a space between the third and fourth digits and between the sixth and seventh digits. (format NNN-NNN-NNN or NNN NNN NNN, where N is a single digit).
  • If an entry is made in this field, the Luhn algorithm is used to verify that the entry is acceptable.

Applied For fields:

  • If the checkbox is selected, then the Applied For Date field must have a date that is the current date or prior.
  • If the checkbox is not selected, then the Applied For Date field must be empty.
Verification rules
  • If there is an entry in the Social Insurance Number field, then:
    • The entry must be valid,
    • The Applied For field must be not selected.
    • The Applied For Date field must be empty.
  • If there is no entry in the Social Insurance Number field, then:
    • The Applied For field must be selected and the Applied For Date field must be acceptable.
Applying the rules
User Input

In this case, the goal is to facilitate the entry into the three fields.

  • The Validation rules are applied whenever there is a change to the data in any of the fields.
    • If any of the validation rules fail, then an error message is displayed to the user.
  • The Verification rules are applied whenever there is a change to any of the three fields:
    • If a Social Insurance number is entered (and valid), then the other two fields must be emptied and disabled.
    • If the Applied For field is deselected, then the Applied For Date field must be emptied and the Social Insurance Number field is enabled.
    • If the Applied For field is selected, then the Applied For Date field is enabled can be changed to a valid date. The Social Insurance Number field must be emptied and disabled.
Data Retrieval

In this case, the goal is to determine if the entries in the three fields are acceptable when data is retrieved.

Scenario 2: Optional Entry

In this scenario, since the entry of the Social Insurance Number is optional, the Applied For field and the Applied For Date fields would be empty and disabled. They are likely to not be displayed to the user.

Validation rules
  • An entry does not need to be made in this field.
    • In this case, this would be treated as an acceptable entry.
  • If an entry is made in this field, the entry must consist of exactly nine or eleven characters:
    • If nine characters, then all characters must be digits.
    • If eleven characters, then there must have exactly nine digits, with either a dash or a space between the third and fourth digits and between the sixth and seventh digits. (format NNN-NNN-NNN or NNN NNN NNN, where N is a single digit).
  • If an entry is made in this field, the Luhn algorithm is used to verify that the entry is acceptable.
Verification rules
User Input

In this case, the goal is to allow the entry into the Social Insurance Number field. The Applied For field and the Applied For Date field are empty, disabled, and not displayed to the user.

  • The Validation rules are applied whenever there is a change to the data in the Social Insurance Number field.
    • If any of the validation rules fail, then an error message is displayed to the user.
  • The Verification rules are applied whenever there is a change to any of the three fields:
    • The Applied For field and the Applied For Date field must both be empty.
    • The Social Insurance Number field must either be empty or contain an acceptable entry.
Data Retrieval

In this case, the goal is to ensure that the entry in the Social Insurance Number field is either empty or contains an acceptable entry and both the Applied For and Applied For Date fields are empty.

Scenario 3: Prohibited Entry

In this scenario, all three fields are to be empty.

Validation rules
  • An entry is not permitted in any of the three fields. The fields may not be displayed to the user.
Verification rules
  • All three fields must not have an entry.
User Input
  • No entry is permitted in the Social Insurance Number field.
Data Retrieval
  • No entry is permitted in any of the three fields.