This article covers:


What is a validated format field

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 should see a Validator field where you enter your regex:

(You can find general guidance on creating booking form fields here).

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 cannot complete the field.

As an example, if you are collecting a ten-digit registration number, you could include the following instructions for your 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

It would then appear as shown below:


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 contact support via live 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 an asterisk * means zero or more characters are allowed within the booking field.

To test this, please see here.

^[0-9]+$ 

Similar to the previous sequence, this one has replaced the asterisk * with a plus sign +. By using a '+', bookers must input one or more characters within the booking field.

To test this, please see 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 see 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 see 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.

  • 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 see 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 see 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.

Return to the top

Did this answer your question?