Skip to main content
All CollectionsFeaturesSheetgo Forms
How to add custom validation to your Sheetgo Forms
How to add custom validation to your Sheetgo Forms

Learn to use regular expression (regex) in your forms

Karoline Fernezlian avatar
Written by Karoline Fernezlian
Updated over 3 months ago

Sheetgo Forms configurations allow you to set the appearance and behavior of your form. You can modify field types and establish dynamic default values. Additionally, you can build custom validations using regular expressions with the [regex:] configuration.

A regular expression is a sequence of characters that specifies pattern to match in texts. You can use it in the form configuration to set specific rules or patterns that need to be followed to fill out a field.

Use cases for regular expressions

You can specify that the field requires a specific word, letter, or number, and even use regex metacharacters to create patterns that match a wide range of variations. If the entered information doesn't meet the criteria, the user will see an Invalid information alert.

Here are some examples:

Required word: Ensure the field contains a specific word. In this case, the user's input needs to include the word "Sheetgo".

[regex: Sheetgo]

Email: Ensure the field contains an email address. You can even specify a certain domain.

[regex: @.*com]

Quantity: Ensure the field contains only numbers.

[regex: [0-9]$]

Website: Ensure the field contains a website address.

[regex: w{3}]

Linkedin Profile: Ensure the field contains a LinkedIn profile URL.

[regex: linkedin.com]

Starting word: Ensure the field starts with a specific word.

[regex: ^hello]

Ending word: Ensure the field ends with a specific word.

[regex: bye$]

Regex metacharacters

There are endless use cases for [regex:]. The validation is built differently for each case. Inside the [regex:] configuration, you can use metacharacters to build strings patterns that user input must match to be valid.

These are some common regular expression metacharacters:

|

Creates an OR clause, where the field needs to include one of the available answers. Example: [regex: dog|cat]

( )

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

?

Indicates zero or one occurrence of the preceding element. Example: colou?r matches both "color" and "colour".

*

Matches zero or more occurrences of the preceding element. Example: ab*c matches "ac", "abc", "abbc", "abbbc", etc.

+

Matches one or more occurrences of the preceding element. Example: ab+c matches "abc", "abbc", "abbbc", 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. Example: a.b matches any string containing "a", followed by any character, then "b". a.*b matches any string containing "a", then any characters, then "b".d then the character "b" at some later point.

[ ]

Defines a character class, matching any single character within the brackets. Example: [a0/] matches the characters "a", "0", and "/".

[^]

Defines a negated character class, matching any single character not within the brackets. Example: [^a0/] matches all characters except "a", "0", and "/".

^

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?