All Collections
Features
Sheetgo Forms
How to add custom validation to your Sheetgo Forms
How to add custom validation to your Sheetgo Forms

Learn how you can use regular expression (regex) inside your form

Eugenia Langen avatar
Written by Eugenia Langen
Updated over a week ago


Using Sheetgo Forms configurations you can describe the appearance and behavior of your form. You can modify field types and establish dynamic default values. You can take this a step further by building a custom validation using regular expression: [regex:].

A regular expression is a sequence of characters that specifies a match pattern in text. Inside the form configuration, you can use it to determine a specific rule or pattern that needs to be respected to successfully fill out the field.

You can specify that the field needs a specific word, letter, or number, and even use regex metacharacters to create a pattern, which can match a wide range of text variations, to successfully submit the field. If the information that is added to the field doesn't meet the criteria the user will receive an Invalid information alert, like the one below.

We can look at some use cases for this configuration:

Required word: You can use regex to determine that in order to complete the field the user needs to add a certain word to it, in this case, the user needs to input "Sheetgo" to complete the field.

[regex: Sheetgo]

Email: You can determine that the user needs to add an email to submit the file, there's a variety of ways to do this. You can even specify a certain domain that the email needs to be.

[regex: @.*com]

Quantity: If you want the user to only be able to add a number, you can use a string that will only validate a numeric sequence.

[regex: [0-9]$]

Website: You can also specify that the user must enter a website address.

[regex: w{3}]

Linkedin Profile: Or you can determine that the field will only be validated with a certain domain name.

[regex: linkedin.com]

Start: If you want the field to start with a specific word you can do this with regex.

[regex: ^hello]

End: And you can follow the same logic if you want the field to end with a specific word.

[regex: bye$]

There are a variety of possible use cases for the [regex:], for each case the validation will be built differently. Inside the [regex: ] configuration you can use the standard metacharacter, which will allow you to build a string that will require the user to add only specific types of information.

At the table below you can find a list of some metacharacters.

|

Creates an OR clause, where the field needs to be completed with one of the available answers. For example: [regex: dog|cat]

( )

Groups expressions together, allowing you to apply quantifiers to entire sub-patterns. For example, gray|grey and gr(a|e)y are equivalent patterns that both describe the set of "gray" or "grey".

?

The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both "color" and "colour".

*

Matches zero or more occurrences of the preceding element. For example, ab*c matches "ac", "abc", "abbc", "abbbc", and so on.

+

Matches one or more occurrences of the preceding element. For example, ab+c matches "abc", "abbc", "abbbc", and so on, but not "ac".

{n}

The preceding item is matched exactly n times.

{min,}

The preceding item is matched min or more times.

{,max}

The preceding item is matched up to max times.

{min,max}

The preceding item is matched at least min times, but not more than max times.

.

Matches any character except a newline. For example: a.b matches any string that contains an "a", and then any character and then "b".a.*b matches any string that contains an "a", and then the character "b" at some later point.

[ ]

Defines a character class, matching any single character within the brackets.

[^]

Defines a negated character class, matching any single character not within the brackets.

^

Matches the start of a line or string.

$

Matches the end of a line or string.

Need more help?

Contact us via chat, on our email ([email protected]), or send us a ticket!

Visit our Community for help, tips, tricks, and feedback for Sheetgo.

Did this answer your question?