Pattern Validations

This type of validation allows you to define a specific pattern or regular expression to control the content in a short or long text-type field.

As for any other validation, you can configure it in Actions > Redesign form, select the field to which you want to apply it, click on Modify, and then on Validations:

Redesign form option

 

Modify field Validations

In the Validations section, you can choose Regular Expression under the Validation type to establish a pattern:

Selecting "Regular expression"

 

Pattern types for validations

 

You can choose different pattern types for your validation and establish a regular expression syntax. 

Enclosing a pattern of characters within square brackets always results in accepting a single character among the list of specified characters. For instance, the expression [abc] would recognize only the a, b, or c character.

To define a negated character, you can use the caret (^) symbol immediately after the first bracket, as in [^abc]. In this example, a,b or c will not be accepted values.

Moreover, you can specify a range of characters, by using the hyphen (-) character inside the square brackets. For instance, [0-9] would accept any single digit from 0 to 9.

Let's see it in examples:

Regular Expression

Description

                       [abc]

It accepts any of the characters a, b, or c.

                      [^abc]

It accepts any character other than a, b, or c.

                       [a-z]

It accepts any character from lowercase a to lowercase z.

                       [A-Z]

It accepts any character from uppercase a to uppercase z.

                       [a-Z]

It accepts any character from lowercase a to uppercase Z.

                       [0-9]

It accepts a single digit between 0 and 9.

                    [a-z0-9]

It accepts a single character between a and z or 0 and 9.

We can also use braces to change the logic of the regular expression. For instance, with this {m,n} nomenclature, being “m” and “n” the limiting values of the number of times that the characters placed before the braces are repeated. 

Let's see the following examples with the letter "p":

Regular Expression

Description

               p{2}

It accepts exactly two repetitions of the letter p.

              p{2,3}

It accepts at least two repetitions of the letter p, but not more than three occurrences of the letter p.

               p{2,}

It accepts two or more repetitions of the letter p.

               p{,3}

It accepts three repetitions of the letter p at most.

 

We can also use the following characters to complement our searches with regular expressions:

  • + accepts one or more repetitions of the character that precedes.
  • * accepts zero or more repetitions of the character that precedes.
  • ? accepts zero or one repetition of the character that precedes.

Let's check its use in the following examples:

Regular Expression

Description

                  p+

It accepts one or more repetitions of the letter p.

                  p*

It accepts zero or more repetitions of the letter p.

                  p?

It accepts zero or one repetition of the letter p.

You can find more info on Regular Expressions here.

 

Autocomplete:

 

If you want to use a predefined pattern, you can do the Autocomplete parameter.

Selecting "EAN"

This dropdown list contains some useful predefined patterns that you can easily choose. In the following table you can see some regular expressions that will be automatically filled as patterns when you select them:

Option

Regular Expression

EAN

[0-9]{13}

ISBN

 

[0-9]{13}

UNSPSC

 

[0-9]{8}

European date

[0-3][0-9]/[0-1][0-9]/[0-9]{4}

International date

[0-9]{4}-[0-1][0-9]-[0-3][0-9]

American date

[0-1][0-9]/[0-3][0-9]/ [1-2][0-9]{3}

Numbers with separators

[0-9]+[-][0-9]+

Decimal number

 

[0-9]+[.,][0-9]+

Once your pattern is set, you can test it by clicking the Verify button. This will show a new textbox Field value test, where you can write the content you expect to be filled in, to verify whether it complies with the pattern or not. Then the Test button will show the result of this verification, therefore you will know if your pattern is ready to be saved.

For the example below, if EAN has been selected in autocomplete, this means that the pattern set for this field is 13 digits, from 0 to 9: [0-9]{13}. Then, if you insert the following numbers in the field value test box, this will be the result:

 

Testing "Field value test"

 

On the other hand, if it doesn't comply with the pattern, it will show the following message:

Error when matching the pattern

 

Note: Remember that this test has the only objective to help you define the pattern, but does not change the content of any fields. Any information in the Field Value Test will not be saved as part of the information, even after saving the pattern validation.

Once the pattern is set and tested, you can click the Modify button to save it.

From now on, every time a value is completed, the validation will show an error or mark it as correct:

 

Correct information validated: 

5

 

Validation error:

4

Tip: The pop-up specifying which validation(s) are defined for the attribute will appear when clicking the green/red check mark next to the field name.