IsMatch
Checks a string to see if it matches another value or a regular expression pattern.
Syntax
IsMatch( StringValue, RegExPattern );
Parameters
| Parameter Name | Type | Description | Optional? | Default Value |
|---|---|---|---|---|
| StringValue | String | The string to validate. | No | n/a |
| RegExPattern | String | The regular expression pattern to compare against the StringValue. This can also be a literal string or a keyword. | No | n/a |
Output
If the string matches the specified regular expression or value, the function will return True; otherwise it will return False.
Use Case
Every resident 16 years and over, within the United Kingdom, has to pay National Insurance Contributions. It is easy to check these contributions on the government website, at any time. Access the Check your National Insurance form, and select the online statement link.
As part of this form, a valid National Insurance number needs to be provided. You are a government administrator, that has to ensure that the correct letters and numbers are entered into the NI text box.
Use the IsMatch function to identify a valid NI number entry:
if(IsMatch(trim(Input), "[A-CEGHJ-PR-TW-Za-ceghj-pr-tw-z][A-CEGHJ-NPR-TW-Za-ceghj-npr-tw-z]\s*\d{2}\s*\d{2}\s*\d{2}\s*[A-Da-d]$"),1,0);
The Trim function deletes any spaces at the beginning and end of a string.
National Insurance numbers follow a simple pattern, two letters followed by 6 numbers and then a letter between A and D. The only constraint is put on the first two letters, which can only be certain letters of the alphabet. For this reason, add a validator to the NI number question in your model:
[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z]\s*\d{2}\s*\d{2}\s*\d{2}\s*[A-D]
Examples of valid inputs are as follows:
- JP617262A
- AW637463B
- WC428107C