Skip to main content

Custom validation in web forms

Updated over 2 months ago

When setting up web forms, you may need to set up validation for fillable fields. Field validation is an automated process that ensures the fields you’ve added contain the correct values entered by recipients.


Select one of the validation formats from the dropdown menu for the fields you want to configure, or adjust your own validation using JavaScript regular expressions.


Example: A recipient needs to fill out a Car registration renewal form and specify the car's registration class (consisting of only three digits). This type of car registration class validation is not included in the list of available validation formats and must be set up via a JavaScript regular expression.


1. Once you’ve added the single line field to your web form, proceed to the field properties panel. In the Validationsection, select the Custom validation format.

Enter the JavaScript regular expression that will allow for adding the validation format you need.


Here we use the following regular expression: ^[A-Z]{3}, where A-Z means that a recipient should enter capital letters, and 3 refers to the maximum number of capital letters recipients should provide.

Tip: Be sure to not add slashes in the beginning and end of the regular expression to avoid duplication. The system will add slashes automatically.

Then, provide a description of what values recipients are expected to enter in the specified single-line field.

If a recipient enters data in another format than what you’ve specified, the field will be instantly highlighted and the recipient will be informed that the data was entered in the wrong format.

Get more information on building JavaScript regular expressions by referring to the tables below:

^abc$

start / end of the string

[abc]

any of a, b, or c

[^abc]

not a, b, or c

[a-g]

character between a and g

a* a+ a?

0 or more, 1 or more, 0 or 1

a{5} a{2,}

exactly five, two or more

a{1,3}

a{1,3}

a+? a{2,}?

a+? a{2,}?

ab|cd

match ab or cd

\w \d \s

word, digit, whitespace

Special sequences

\A

Matches if the specified characters are at the start of a string.

\b

Matches if the specified characters are at the beginning or end of a word.

\B

Opposite of \b. Matches if the specified characters are not at the beginning or end of a word.

\d

Matches any decimal digit. Equivalent to [0-9]

\D

Matches any non-decimal digit. Equivalent to [^0-9]

\s

Matches where a string contains any whitespace character. Equivalent to [ \t\n\r\f\v]

\S

Matches where a string contains any non-whitespace character. Equivalent to [^ \t\n\r\f\v]

\w

Matches any alphanumeric character (digits and alphabets). Equivalent to [a-zA-Z0-9_]. By the way, underscore _ is also considered an alphanumeric character.

\W

Matches any non-alphanumeric character. Equivalent to [^a-zA-Z0-9_]

\Z

Matches if the specified characters are at the end of a string.

Digits

^\d+$

Whole numbers

^\d*\.\d+$

Decimal numbers

^\d*(\.\d+)?$

Whole and decimal numbers

^-?\d*(\.\d+)?$

Negative, positive whole and decimal numbers

[-]?[0-9]+[,.]?[0-9]*([\/][0-9]+[,.]?[0-9]*)*

Whole, decimal, and fractions

Alphanumeric characters

^[a-zA-Z0-9]*$

Alphanumeric without space

^[a-zA-Z0-9 ]*$

Alphanumeric with space


Did this answer your question?