Skip to main content
Using 'validated format' fields

Ensure that you receive booking form field answers in your required format by using regex

Anni avatar
Written by Anni
Updated over a year ago

This article covers:


What is a validated format field

You can create a booking form field that has a specific response requirement, such as requiring that a phone number field only contains numbers and is exactly 11 digits.

To do this, you use something called a 'regex' (regular expression) when setting up your field. This is a sequence of characters that defines the 'valid' input.

Regex ensures accurate data entry by preventing customers from completing a field if it doesn't match the defined format.

💡 We suggest only using regex if you're comfortable with it or have faced issues with incorrect data.


Creating a validated format field

You can create 'validated format fields' by selecting Settings in the left-hand menu, then Booking fields.

From here, either select Edit next to an existing field or select Add new field type:

You can add in all of your relevant information, such as Field label, etc.

Then select Plain text - single line - validated format from the Field data type drop-down menu. From here, you can add your regex into the field under the Validator box (if already created. Otherwise, create your regex) :

  • Typically, regex code begins with '/' and ends with '/g', but our validated format fields automatically 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 requirement in the Additional help text field and/or the Example input (placeholder) field to help your customers understand what is required to complete the field:

You may also wish to include a contact email address/telephone number so that customers can reach out to you directly if they cannot complete the field.

For example:

  • In the Additional help text, you could add:

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

  • In the Example input (placeholder):

    • "1234567890"

It would then appear as shown below:


Creating a regex

Here are some commonly used regex codes:

Numbers only

  1. Zero or more (Numbers only).

^[0-9]*$ 
  • Example valid responses: 123456789, 123, 0000, 7, etc.

  • Example invalid responses: 12345678a, 123.4, abcd, @, etc.

Using an asterisk (*) in the code means no characters are allowed within the booking field.

2. One or more (Numbers and characters accepted).

^[0-9]+$ 

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

  • Example valid response: 1234a, +44, abc90, etc.

  • Example invalid responses: 123456, 98740, 89, etc.


Alphanumeric (without spaces)

Any sequence of alphanumeric characters without spaces will be accepted in this field.

^[a-zA-Z0-9]*$
  • Example valid inputs: a1b2c3d4, aaaaa, 12345, Ab12CD34

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


Alphanumeric (with spaces)

Any sequence of alphanumeric characters with spaces will be accepted in this field.

^[a-zA-Z0-9 ]*$
  • Example valid inputs: a BCDe, 123456, ABC 123, 000 999

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


Number range

Determine the number of characters that your customer must input for a valid response. This could be a specific number or a range of numbers.

Replace the asterisk (*) with these brackets { } that contain your desired character number (or number range).

For example:

Instead of:

^[0-9]*$ 

The code would be:

^[0-9]{8}$ 
  • This indicates that the field will only accept 8 numbers.


Lowercase characters

Restrict the field to lower-case characters only.

Add the lowercase requirement in the [ ] brackets, for example, "a-z".

You can restrict this further by replacing the asterisk (*) with these brackets { } that contain your desired character number (or number range).

For example:

^[a-z0-9]{7,10}$ 
  • This code only permits inputs of 7, 8, 9, or 10 characters and doesn't allow upper-case characters.

💡 To ensure the best performance, please use a regular expression format compatible with the latest version of Ruby (such as PCRE).


Testing regex

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


💬 Any questions or feedback? There are two ways to get in touch:

Thank you! 🕺

Did this answer your question?