Articles on: Build & Customize

How to set customized validation (RegEx) on your form fields

When you create a form with data input fields, it is essential to validate the data and make sure that your user inputs are accurate. Customized validation on your form fields lets you do that.

This tutorial shows how you can validate the data and make sure that your user inputs are accurate.

Using the “Custom Validation” field in your form editor, you can restrict your audience to enter information in a specific format.

So how does it work?

The custom validation field lets you define what input is valid to be inserted. This field has a “Validation rule” property you can set to specify what’s valid and what’s not. The Validation Rule follows the Regular Expression (or RegEx) rules.

Read on to learn how you can leverage the RegEx rules for your validations.

Restrict input to start/end with something

To restrict your field to accepting input that starts with a specific value, you can use the ^ character at the beginning of that specific value. For example, to accept words that start with “dog” put ^dog as your Validation Rule.

To have your audience enter values that end with a specific value, you can use the $ character at the end of that specific value. As an example, to accept values that end with “dog” put dog$ as your Validation Rule.

Now let’s mix and match! If you set ^cute dog$ as your Validation Rule, it will accept input that starts with and ends with “cute dog”. And I mean the exact match, nothing else.

Accept input that includes a specific text

Simple! Put that text into the Validation Rule property. It will match any input that has that text in it.

Make sure a specific number of characters are inserted

Quantifiers help you with that. For example, 003* matches an input that has _00_ followed by zero or more _3_‘s. While 003+ matches inputs that have _00_ followed by at least one _3_ (one or more _3_‘s).

And 003? makes sure the input contains _00_ followed by zero or one _3_.

Also, 003{5} matches inputs that contain _00_ followed by exactly five _3_‘s.

Make sure the exact order of value is inserted

To make sure the order of characters in the inserted value is exact, you can use parentheses. For example, a(bc)* as your Validation Rule, makes sure the inserted value has an _a_ followed by zero or more copies of the sequence _bc_.

Use “OR” to set a variation of the Validation Rule

It gets more interesting when you know you can set different variations on your custom validation field. You can use | as the OR sign and add multiple rules in between. For example, Hi|Hello matches an input that has either Hi or Hello in it.

For example, (b|cd)ef accepts values that have either _bef_ or _cdef_ in them.

When you want to accept any single character

A period character (.) stands for any single character. For example, a.[0-9] matches inserted values that have an _a_ followed by one character and a single digit number between zero and nine.

Also, ^.{3}$ accepts input values with exactly 3 characters.

Specify which characters or numbers are allowed

You can use brackets for that purpose. As an example, [ab] matches any input that has either an _a_ or a _b_ (works the same as a|b). Also, [a-d] matches values that have lowercase letters ‘**a**‘ through ‘**d**‘. (works the same as a|b|c|d and even [abcd]).

Let’s mix and match to see what we can do so far!

^[a-zA-Z] makes sure that the inserted value starts with a letter.

[0-9]% accepts the inserted value only if it has a single-digit number before a percent sign.

,[a-zA-Z0-9]$ matches with input values that end in a comma followed by a letter or a number.

Test it out!

To make sure your custom validation is working as expected, you should test it for yourself and see how your changes are working. Go to your Formaloo dashboard now and add a custom validation field to try it out. You can also use this RegEx pattern tester to test and see what values your validation rule accepts. It will automatically highlight the matches it finds in the textbox below.


The data validation in your form will ensure that only valid information is entered. This prevents a user from entering invalid data, which can negatively impact the integrity of your data.

The “Custom Validation” field in your form editor helps you restrict your audience to enter information in a specific format.

Remember to subscribe to Formaloo blog posts to receive the latest tips and tricks on making the most out of your data-driven journey.

Updated on: 22/01/2023

Was this article helpful?

Share your feedback


Thank you!