How to Create a Regular Expression Mask

This topic provides information to help you create a regular expression mask. For more information on regular expression language, see https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx. Once created, you can validate the expression at https://regexr.com/. Below is a list of the components that can be used in regular expression masks for Text attributes.

    Metacharacters: These are used to represent a range of symbols corresponding to valid text that can be entered in the field.

. – indicates that any character can be used.

^[aeiou]*$ – indicates which characters can be used. In this case, for example, only the letters "a", "e", "i", "o", or "u" should be used.

[^aeiou] – indicates which characters cannot be used. In this case, for example, only the letters "a", "e", "i", "o", or "u" cannot be used.

[a-zA-Z0-9] – indicates the interval of characters or numbers that can be used. In this case, the letters "a" to "z" in upper or lower case can be used, as well as numbers from 0 to 9.

\w – indicates that any alphanumeric characters can be used. This is the same as the expression [a-zA-Z0-9].

\W – indicates that any characters that are not alphanumeric can be used. This is the same as the expression [^a-zA-Z0-9].

\d – indicates that any decimal digits can be used. This is the same as the expression [0-9].

\D – indicates that any characters that are not digits can be used. This is the same as the expression [^0-9].

    Quantifiers: These are characters that indicate the number of repetitions for the expressions preceding them.

* - indicates zero or more repetitions. For example, the expression [a-z]* indicates that zero or any number of the letters "a" to "z" should be entered for the content to be considered valid.

+ - indicates one or more repetitions. For example, the expression [0-9]+ indicates that one or more digits from 0 to 9 should be entered for the content to be considered valid.

? – indicates zero or one repetitions. For example, the expression [http://]? indicates that "http://" should be entered never or once for the content to be considered valid.

{n} – indicates the exact number of repetitions that should be entered. For example, the expression [aeiou]{2} indicates that two of the vowels specified should be entered: "aa", "ae", "io", "ii", etc.

{n,} – indicates the minimum number of repetitions. For example, the expression [A-Z]{3,} indicates that at least three of the letters should be entered: "AAA", "XPTO", "XYZAA", and so on.

{n,m} – indicates the minimum (n) and maximum (m) number of repetitions. For example, the expression [0-9]{2,3} indicates that at least two and at most three digits from 0 to 9 should be entered: "123", "247", "27", "33", and so on.

    OR operator: This operator is used to indicate conditions that must be met for the text entered in the field to be considered valid.

| - this symbol is used to indicate exclusive disjunction. For example, the expression [(http://|ftp://)?] indicates that either "http://" or "ftp://" should be entered for the text entered to be considered valid.

    Special characters: These are used to represent delimiters and monetary symbols.

/ - this character is used to separate months, days, and years in dates. It may be culture dependent and replaced by the appropriate option. For example, to insert a date, the digits of the month should be entered separated by "/", then the digits of the day should be entered separated by "/", and finally the digits for the year should be entered. If a period "." or some other symbol is used to separate dates this should be indicated in the regular expression mask, and the period or symbol to be used to separate them should be entered.

: - this character is used to separate hours, minutes, and seconds. It may be culture dependent and replaced by the appropriate option. For example, to enter a date, the hour should be entered followed by a colon, then the minutes should be entered followed by a second colon for the seconds. If a period "." or some other symbol is used to separate hours, minutes, and seconds this should be indicated in the regular expression mask, and the period or symbol to be used to separate them should be entered.

$ - this character is used to indicate a monetary value. It may be culture dependent and complemented or replaced by the appropriate option. For example, to enter a monetary value in dollars, the dollar sign "$" should be inserted followed by the digits. If the currency is the Canadian dollar "C$", this should be indicated in the regular expression mask to require that "C$" be entered before the digits to indicate the specific currency.

    Literal characters: These are characters that are not used to represent metacharacters, quantifiers, operators, or special characters. To use a character reserved as a literal character, a backslash "\" must precede it. For example, if you want a period to be included in the content entered in the field, a backslash should be inserted before it in the mask: ([a-z]\.[a-z]).

    Examples of regular expression masks: The above components should be combined as needed to create masks. Note that parentheses should be used to associate expressions with each other.

Date (mm/dd/yyyy): ^([1-9]|0[1-9]|1[0-2])/([0-9]|[0,1,2][0-9]|3[0,1])/\d{4}

([a number between 1 and 9], or the number 0 [followed by a number from 1 to 9], or the number 1 [followed by 0, 1, or 2]), a slash "/", ([a number between 0 and 9], or [the number 0, 1, or 2] [followed by a number from 0 to 9], or the number 3 [followed by 0 or 1]), a slash "/", a number between 0 and 9 {with exactly four repetitions}

E-mail: ([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(\.){1}[a-zA-Z]{2,4})+

([a number between 0 and 9, the letters "a" to "z" in either upper or lower case] repeated one or more times (["_", ".", "-") repeated never or once [a number between 0 and 9, the letters "a" to "z" in upper or lower case] repeated one or more times) this expression should be entered zero or more times, an "@", [a number between 0 and 9, the letters from "a" to "z" in upper or lower case] repeated one or more times [a number between 0 and 9, the letters from "a" to "z" in upper or lower case, ".", "-"] this expression should be entered zero or more times, enter a period just once, [the letters from "a" to "z" in upper or lower case] {repeated at least twice and at most four times] an e-mail in this format can be entered one or more times

Image file: [a-zA-Z0-9-_\.]+\.(jpg|gif|png)

[the letters from "a" to "z" in upper or lower case, a number between 0 and 9, an underscore "_", a period "."] repeated one or more times, a period ".", (followed by jpg or gif or png)

IP address: ((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})

((the number 25 [followed by a number from 0 to 5], or [the number 2 followed by a number from 0 to 4], [followed by a number from 0 to 9], or the number 1 [followed by a number from 0 to 9] {repeated twice}, or [a number from 0 to 9] {repeated at least once and at most twice}), enter a period ".", {this first expression should be repeated three times}, (the number 25 [followed by a number from 0 to 5], or the number 2 [followed by a number from 0 to 4] [followed by a number from 0 to 9], or the number 1 [followed by a number from 0 to 9] {repeated twice}, or [a number from 0 to 9] {repeated at least once and at most twice})

Time: ([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1}

([a number from 0 to 1] [followed by a number from 0 to 9] or [the number 2] [followed by a number from 0 to 3]), [enter a semicolon ":" ([a number from 0 to 5] [followed by a number from 0 to 9])) {this expression should be entered at least once}

URL: (http[s]?://|ftp://)?(www\.)?[a-zA-Z0-9\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov|br)

(http [with s or not]:// or ftp://) entered never or once, (enter "www" and a period) entered never or once [the letters from "a" to "z" in upper or lower case, a number between 0 and 9, and a period "."} repeated one or more times, enter a period ".", (and enter "com", "org", "net", "mil", "edu", "ca", "co.uk", "com.au", "gov", or "br")