Regular expressions are patterns used to match character combinations in strings. A pattern may include single- or multi-character literals, operators, and constructs.
You can use regular expressions in String type fields to create input masks. They are used to validate data that a user enters against the defined rules. Note that masks can only include expressions without flags.
You can also enter a message that will be displayed in case the data entered by the user doesn’t match the regular expression pattern.
Learn more about the syntax of regular expressions on the MDN Web Docs website.
All examples below include the following special characters:
‘^’ matches the beginning of input,
‘$’ matches the end of input,
‘?’ in ‘()?’ matches the preceding item 0 or 1 times. If this character is not added after the parentheses, and the field is left empty, the system will display an error message even if the field is not marked as required.
Examples of regular expression patterns
Validate a US passport number
^(([0-9]{8})|([0-9]{9}))?$
Let’s break it down:
- [0-9]{8} allows entering eight digits.
- [0-9]{9} allows entering nine digits.
- (a|b) allows entering either the left or the right part of the expression.
Examples:
- 12345678
- 123456789
Validate a US Social Security number
^([0-9]{3}[-]{1}[0-9]{2}[-]{1}[0-9]{4})?$
Let’s break it down:
- [0-9]{3} allows entering three digits.
- [0-9]{2} allows entering two digits.
- [0-9]{4} allows entering four digits.
- [-]{1} allows entering one ‘-’ character.
Example: 123-45-6789
Validate a US Employer Identification Number
^([0-9]{2}[-]{1}[0-9]{7})?$
Let’s break it down:
- [0-9]{2} allows entering two digits.
- [-]{1} allows entering one ‘-’ character.
- [0-9]{7} allows entering seven digits.
Example: 12-3456789
Validate a Legal Entity Identifier
^([0-9]{4}[0]{2}[A-Z0-9]{12}[0-9]{2})?$
Let’s break it down:
- [0-9]{4} allows entering four digits.
- [0]{2} allows entering the ‘0’ character twice.
- [A-Z0-9]{12} allows entering twelve alphanumeric characters (uppercase Latin letters or digits).
- [0-9]{2} allows entering two digits.
Example: 123400AB123456789612
Validate a file name
^([^\\/:*?"<>|]+[.]{1}[^\\/:*?"<>|]+)?$
Let’s break it down:
- [^\\/:*?"<>|] allows entering any characters except for the ones after ‘^’ (in other words, the characters included in the range are negated).
- [a]+ allows entering the characters in the brackets one or more times. In this case, it allows you to enter any combination of characters except for the ones specified in the brackets.
- [.]{1} allows entering one period.
Example: Document1.docx
Validate a file path
^(([A-Z]:\\){1}[^\/:*?"<>|]+)?$
Let’s break it down:
- ([A-Z]:\\){1} allows you to enter one uppercase Latin letter and the ‘:\’ sequence of characters (the first ‘\’ tells the system that the next backslash is not a special character).
- The ‘+’ character allows entering the characters in the brackets one or more times. In this case, it allows you to enter any combination of characters except for the ones specified in the brackets due to the ‘^’ character at the beginning of the range.
Examples:
- C:\Windows\System32\calc.exe
- Z:\test.txt