In Formulayt, custom validation rules can be added to fields in the manage fields area. This allows you to create very specific requirements for fields to be considered valid.


These validation rules use regular expressions to ensure that the input entered by a user matches the required format. You should be comfortable writing regular expressions before using this feature. If you're new to regular expressions, you can check out one of the many tutorials online. Additionally, Regex101 provides an excellent tool for quickly building and testing regular expressions before using them on your Formulayt account.


If a custom validator has been added, any value that the user enters into the field must match against the regular expression to be considered valid.

 

Regular expression validators should always be tested in preview mode before publishing them to ensure they work as intended and don't inadvertently prevent all form submissions. 


In addition, care should be taken to specify a meaningful error message that explains to the user exactly what they need to do to pass validation. For example:

"Please enter a business email address"

Is much better than:

"Email address not valid"


Examples regular expressions

The below examples show some useful examples that you can


Allow only alpha characters

To allow only letters to be entered, you can use the following:

^([a-zA-Z]*)$


To allow spaces as well, you can amend this to:

^([a-zA-Z\s]*)$


Allow only numbers

To allow only numbers, you can use the following:

^([0-9]*)$


Block specific email domains

This is achieved using a negative lookahead:

.+@(?!example1\.|example2\.|example3\.)

The domains are added in this section: example1. example2.  and example3. Importantly, these must be pipe separated, and each period must be preceded by a backslash. This will also match any TLD variant, for example, example1.co.uk or example1.com would both be blocked by this regular expression.


Here is the same regular expression with common personal email domains which you can adapt as necessary for your purposes:

.+@(?!gmail\.|hotmail\.|me\.|ymail\.|yahoo\.|mac\.|live\.|me\.|msn\.|outlook\.)


Block URLs

This is also achieved using a negative lookahead to block anything that matches a URL pattern:

^(?!.*(telnet|ftp|https?):\/\/(?:[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\.|[a-z0-9]\.)+[a-z]{2,63})