Validating Text and Numeric Fields

Validation ensures that only certain values are entered in a field. Validation functionality is available for text and numeric fields.

To enable validation,

  1. Add a Text or Numeric field to a form in the Builder view.

  2. Open the field’s Properties tab.

  3. Turn on the Validation toggle to enable validation and open its configuration options.

Figure 1: Validate data to ensure youre collecting only useful information.

Figure 1: Validate data to ensure you're collecting only useful information.

Validating Text Fields

Validation for text fields contains several options. You must first choose a list of available conditions to check:

  • If Input Contains
  • If Input Does Not Contain
  • If Input Is not URL
  • If Input Is not Email
  • If Input Does not Match

If the condition isn’t met, an error message is displayed to the user. Where you go from there depends on which condition you used.

If Input Contains/Does Not Contain

When you validate text data to check if it contains a certain value, there are two additional steps to take after selecting the condition:

  1. Enter the text to check for.

  2. Enter an error message so users understand why their submission failed.

Figure 2: If Liferay isnt part of the fields value, an error message is displayed.

Figure 2: If *Liferay* isn't part of the field's value, an error message is displayed.

If Input Is not URL/Email

Checking for properly formatted URLs and emails is easy. Just choose the condition from the If Input drop-down and enter the error message.

Valid URLs begin with http:// or https://. Valid emails must contain @.

Figure 3: Use text field validation to make sure users enter a valid email address or URL.

Figure 3: Use text field validation to make sure users enter a valid email address or URL.

If Input Does Not Match

The Does Not Match condition is used for entering regular expressions to create custom validation criteria. For example, use this regular expression to ensure that ten consecutive numeric digits are entered in a phone number field:

^[0-9]{10}$

If you use regular expression validation, provide some explanatory text (e.g., help text, placeholder text, and a clear error message) to guide form users in entering the proper data.

Figure 4: Regular expression text validation opens up countless possibilities.

Figure 4: Regular expression text validation opens up countless possibilities.

Validating Numeric Fields

Numeric field validation is similar to text field validation, but the conditions compare the value of the number entered to some other value.

Figure 5: Numeric conditions constrain user-entered numeric data.

Figure 5: Numeric conditions constrain user-entered numeric data.

Available conditions to check include

  • Is greater than or equal to
  • Is greater than
  • Is not equal to
  • Is less than or equal to
  • Is less than

For example, to make sure users don’t enter a number over 10, enable validation and use Is greater than with a value of 10. Use the message Please enter 10 or less.

Figure 6: Make sure user-entered numeric data is within reasonable bounds. Nobody needs 11 sandwiches for lunch.

Figure 6: Make sure user-entered numeric data is within reasonable bounds. Nobody needs 11 sandwiches for lunch.

Note that numeric fields are text fields validated to allow only numeric data entry. That’s why they’re in the Customized Elements section of the form fields list. In addition, the property My numeric type is (can be Integer or Decimal) on the Basic tab of a numeric form is another form of validation.

« Help Text, Placeholder Text, and Predefined ValuesEnabling CAPTCHA on Form Submissions »
Was this article helpful?
0 out of 0 found this helpful