REGEX_MATCH
The REGEX_MATCH function searches each item in an array for a match against a regular expression pattern. It returns the relative position (starting at 1) of the first match found, or 0 if no matches are found.
Use
REGEX_MATCH( text, pattern )
Check if text matches the specified regular expression pattern.
| Parameter | Required | Description |
|---|---|---|
| text | Yes | the text to search |
| pattern | Yes | the regular expression to match |
| Returns | Logical |
Examples
Validating Corporate ID Formats
You can use REGEX_MATCH in an Output Validation formula to ensure that users follow a specific naming convention when entering data into a form.
- Scenario: A company requires all "Account Numbers" to begin with the prefix "ADT" followed immediately by exactly 7 digits.
- Formula:
ASSERT(REGEX_MATCH(this, "^ADT{7}$") > 0, "Account number must start with ADT followed by 7 numbers."). - Logic:
this: Refers to the value the user is currently entering into the capture widget."^ADT{7}$": This is the regular expression pattern.- Result: If the user enters "ADT1234567", the function returns 1 (the position of the match). Since 1 is greater than 0, the validation evaluates to TRUE. If they enter "ABC1234567", it returns 0, triggering the
ASSERTerror message.
Prohibiting Specific Characters (Character Restrictions)
By combining REGEX_MATCH with the NOT function, you can create rules that prevent users from entering prohibited characters, such as spaces or symbols.
- Scenario: A "System Username" field must not contain any spaces to prevent errors in downstream databases.
- Formula:
ASSERT(NOT(REGEX_MATCH(this, " ") > 0), "Usernames cannot contain spaces."). - Logic:
REGEX_MATCH(this, " "): This searches the input for a space character.NOT(...): This function reverses the logical result.- Result: If a space is found,
REGEX_MATCHreturns a number greater than 0. TheNOTfunction then turns that "TRUE" state into FALSE, which causes theASSERTfunction to block the submission and display the error message.