set customized validation on your form fields

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

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-Z 0- 9]$ matches with input values that end in a comma followed by a letter or a number.

Specify how many digits to have: For example an 8 digit code

You can use a range quantifier {min,max} to specify a minimum of 1 digit and a maximum of 8 digits as:

^[0-9]{1,8}$

Explanation:

^     : Start anchor
[0-9] : Character class to match one of the 10 digits
{1,6} : Range quantifier. Minimum 1 repetition and maximum 6.
$     : End anchor

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.

Check out and pick this template for the most requested custom validations. You can get an idea of how you can customize your forms’ validations using it.

Conclusion

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.

How to connect Formaloo with other tools using Make (Integromat)
What’s New in Formaloo: April 2022
How to query Formaloo using GraphQL (beta)

Getting started is easy

Start organizing your data with Formaloo.

This website uses cookies to ensure that you get the best experience.