Skip to content Skip to main navigation Skip to footer

How to Create Custom Question Validation

When creating an entry form Nucleus provides a multitude of pre-defined question types that are used to validate the answers provided by entrants. An email question validates that the answer is an email and the phone number question validates that an answer is a phone number. However, there are circumstances where your requirements may not be met by the existing question types. In these instances, admins can create their own question validation rules and apply these to the existing question types.

For example, you might want to validate that the answer provided by the entrant is currency. In this instance, we need to use a text box, as we want to include a £ sign and a however, there is nothing to prevent the users from providing an answer that contains no numbers.

To achieve this we can use create a custom validation rule that forces the user to format their answer as follows: £[numbers].[two_numbers] or £14.53

We do this using simple queries called Regular Expressions. This help guide will cover how to apply the above example to illustrate how the functionality works. This guide will not cover how to write regular expressions. If you would like a specific question validation please submit a support ticket and the BMT Support team can assist you in its creation.

How to Create a Validation Rule

The instructions below will explain how to create the validation rule. See below to see how to apply the rule to a specific question type.

  1. Log into the Admin Interface
  2. Go to Actions>Misc
  3. In the System Administration section select Validation Rules
  4. Click Add to create a new rule
  5. Add a Name for the rule, in this case we will enter Currency (£)
  6. Enter the Regular Expression, this is the code that you have created and in this case we will enter [£]\d+[.]\d{2}
  7. Enter an Error Message, this will be shown to the entrant when they enter the wrong values and the answer does not pass the validation rule.
  8. Choose the question types to which you want to apply the rule. It is unlikely that all validation rules can be applied to all question types so think carefully about how you want to apply the rule.
  9. Click Save and Close

How to Apply a Validation Rule to a Specific Question

  1. Log into the Admin Interface
  2. Go to Actions>Question List
  3. Click Edit on a relevant question or click Add to create a new question
  4. If the question type has a validation rule available, see the above section for how to create the rules, you will see a dropdown Validation Rule appear at the bottom of the Question Parameters
  5. Select the relevant rule from the drop-down
  6. Update the rest of the question options as required – for more information about questions please see the creating an entry form guide
  7. Click Save and Close
  8. When the entrant provides data for the question the validation rule will be tested before the user can submit the form

Note – Only one validation rule can be applied to each question.