How to add a custom validation to your Sheetgo forms
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.
patterns used for searching, matching, and manipulating text in strings. They are commonly used in programming, text processing, and data extraction tasks. Regex allows you to define specific search criteria by specifying a pattern, which can match a wide range of text variations.
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 to it, in this case the user needs to input "Sheetgo" to complete the field.
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.
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.
Website: You can also specify that the user must enter a website address.
Linkedin Profile: Or you can determine that the field will only be validated with a certain domain name.
Start: If you want the field to start with a specific word you can do this with regex.
End: And you can follow the same logic if you want the field to end with a specific word.
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 the 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".
The preceding item is matched exactly n times.
The preceding item is matched min or more times.
The preceding item is matched up to max times.
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.