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:
Selecting Settings in the left-hand menu on your account, then Booking fields.
Select the relevant tab, then Create field:
Confirm that you have selected the correct Field type, then select Plain text - Single-line - Validated from the Data type drop-down menu:
Select Continue to confirm the selection and open the setup screen.
Add all of the relevant field information, including Field question, Additional details and Placeholder text:
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".
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.
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
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."
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:
For a quicker response, please contact us via live chat on our homepage or your account.
Or send us an email
Thank you! πΊ
Return to the top β¬οΈ