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 3 weeks ago

This article covers:


What is a validated format field

A validated format booking form field ensures that customers provide the correct type of information by setting specific requirements for their responses, such as requiring a phone number field to only contain numbers and be exactly 11 digits.

Regex (Regular expression)

To achieve this, you use something called 'regex', which is a sequence of characters that defines the 'valid' input for that field. Regex helps prevent errors by stopping customers from completing a field if their answer doesn't match the required format.

πŸ’‘ Tip: We suggest using regex only if you're comfortable with it or have encountered issues with incorrect data.


Creating a validated format field

To create validated format fields:

  1. Selecting Settings in the left-hand menu on your account, then Booking fields.

  2. Select the relevant tab, then Create field:

    Booking fields screen with an arrow pointing at the 'Create a field' button

  3. Confirm that you have selected the correct Field type, then select Plain text - Single-line - Validated from the Data type drop-down menu:

    Plain text - Single-line - Validated from the Data type drop-down menu highlighted

  4. Select Continue to confirm the selection and open the setup screen.

  5. Add all of the relevant field information, including Field question, Additional details and Placeholder text:

    Booking field setup with the field question, additional details and placeholder text fields highlighted

  6. It's good practice to add any rules into the Additional details and Placeholder text section, as this will help your customers when they complete the fields. For example:

    • In Additional details, 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 Placeholder text, you could add: "1234567890".

  7. You'll need to add your regex into the Set validating rule field under the Validator box. If you have already created it, simply add it in, then select Create field.

  8. Otherwise, you'll need to create your regex.


Creating a regex

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

Typically, regex code starts with '/' and ends with '/g', but with our system, these characters are automatically included. You only need to enter the characters contained between the '/' and '/g' when setting up your validation.

Some commonly used regex codes:


Numbers only

  1. Zero or more (Numbers only).

The code:

^[0-9]*$ 

This allows only numbers and zero or more characters in the field.

Example valid responses: 123456789, 123, 0000, 7, etc.

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

  • The asterisk (*) means no characters are allowed in the booking field.

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

The code:

^[0-9]+$ 

This requires at least one character (number or letter) in the field.

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

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


Alphanumeric (without spaces)

The code:

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

This allows letters and numbers but no spaces or special characters.

Example valid inputs: a1b2c3d4, aaaaa, 12345, Ab12CD34

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


Alphanumeric (with spaces)

The code:

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

This allows letters, numbers, and spaces but no special characters.

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

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


Number range

To specify the number of characters your customer must enter for a valid response, use {} to define the desired character count or range.

Exact number of characters

For example, if you need exactly 8 numbers:
​^[0-9]{8}$
This will only accept 8 numeric characters.

Example valid inputs: 12345678, 98765432

Example invalid inputs: 1234567, 123456789, abc12345

Range of characters

For example, if you want to allow a range of 5 to 10 digits:
​^[0-9]{5,10}$
This will accept any number of digits between 5 and 10.

Example valid inputs: 12345, 987654, 1234567890

Example invalid inputs: 1234, 12345678901


Lowercase characters

To restrict the input to lower-case characters only, use [a-z] inside the regex. You can further specify a character range or a fixed number of characters.

Lowercase only, no upper-case

^[a-z]{7,10}$
This will only accept lower-case characters, with a length between 7 and 10 characters.

Example valid inputs: abcdefg, abcdefghi, abc1234

Example invalid inputs: ABCDEF, AbCdef, 123ABC, aBcD


Testing regex

It's strongly recommended to test all regex expressions before using them in your validated booking form fields. This ensures that the expressions are correct and meet your specific requirements.

Testing helps avoid errors and ensures the form behaves as expected, making data collection accurate and seamless for both you and your customers.


Example: Setting Up a Validated Registration Number Field

In this example, the account has set up a "Registration Number" field using a validated format that only allows numbers:

  • Field name: Registration Number

  • Validated format: Numbers only

  • Placeholder text: "123456789" (This provides an example of the correct type of response).

  • Additional details: "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."

Attendee details section of the checkout with an arrow pointing at a 'Registration Number' field

This setup ensures that the customer enters a valid registration number while providing helpful information and support contact in case of problems.


πŸ’¬ Any questions or feedback? There are two ways to get in touch:

Thank you! πŸ•Ί

Return to the top ⬆️

Did this answer your question?