Plain text - single line - validated format fields use regex to determine how your bookers can answer a booking form field. A regex (regular expression) is a sequence of characters that defines a valid input.

For instance, a regex could determine that a booking form field asking for a booker's telephone number can only be completed if no characters other than numbers are entered. Further, it could ensure that only telephone numbers with 11 digits are accepted.

By design, regex can prevent your bookers from completing a booking form field, and therefore a booking, if their data entry does not match the format you have defined. You must understand precisely what your regex expression calls for and communicate this to your bookers.

Regex is only recommended for those confident in its use or who have had problems with incorrectly entered data in the past. Our support team are always happy to discuss your requirements and answer any questions you may have.


Creating a validated format field

To ensure the best performance, please use a dialect compatible with the latest version of Ruby, such as PCRE.

Validated format fields are created via Settings, then Booking fields, by selecting 'plain text - single line - validated format' from the Field data type drop-down menu (you can find general guidance on creating booking form fields here).

You should see a Validator field where you enter your regex.

Typically, regex code begins with '/' and ends with '/g', but our validated format fields incorporate these characters, so you only need to enter the characters contained within '/' and '/g' when defining your validation.

It's recommended to explain the form validation in the additional help text field and/or the example input (placeholder) field to help your bookers understand what is required to complete the field. In addition, you may wish to include a contact email address/telephone number so that people can reach out to you directly if they are unable to complete the field.

As an example, if I was collecting a ten-digit registration number, I could include the following instructions for my bookers:

Additional help text: Please check to ensure that you enter your ten-digit registration number. Numbers with fewer or greater than ten digits cannot be accepted. Contact support@bookwhen.com if you are unable to complete it.

Example input (placeholder): 1234567890


Creating a regex

Regex is a powerful tool that has many applications. This help article will cover a few useful expressions and basic functions. Any validation formats not covered below could be possible. Please get in touch with us via our website chat or email for help with putting together other expressions.

Here are some commonly used regex codes:

^[0-9]*$

Only numbers will be accepted in the field.

Example valid inputs: 123456789, 123, 0000, 7

Example invalid inputs: 12345678a, 123.4, abcd, @

Using a * means zero or more characters allowed within the booking field.

To test this, please click here.

^[0-9]+$

Similar to the previous sequence, this one has replaced the * with a +. By using a +, bookers will need to input one or more characters within the booking field.

To test this, please click here.

^[a-zA-Z0-9]*$

Any sequence of alphanumeric characters without spaces will be accepted.

Example valid inputs: a1b2c3d4, aaaaa, 12345, Ab12CD34

Example invalid inputs: a1b2 c3d4, a.a.a.a., £12345, A bcde

To test this, please click here.

^[a-zA-Z0-9 ]*$

As above, but spaces are permitted

Example valid inputs: a BCDe, 123456, ABC 123, 000 999

Example invalid inputs: a/b/c/d, 123.456, ABC @123, 999!

To test this, please click here.

Regex can also determine the number of characters that must be inputted for a valid response. This could be a specific number or a range of numbers. Just replace * with these brackets { }, containing your desired character number (or number range).

For example,

^[a-zA-Z0-9]{8}$ indicates that only alphanumeric inputs (with no spaces) that are exactly 8 characters long are valid

To test this, please click here.

^[a-z0-9]{7,10}$ is the same as above, only it permits inputs of 7, 8, 9, or 10 characters and doesn't allow upper case characters.

To test this, please click here.

You can find further advice on putting together regex expressions here.


Testing regex

It is strongly recommended that you test all regex expressions here before implementing validated booking form fields. This will help you ensure that the expressions are validated according to your requirements.

Did this answer your question?