Validation and Masking

Certain Forms fields can be validated (Text, Date, and Numeric fields) and masked (Numeric fields) to ensure User input is valid.

note

Date Fields can be validated beginning in Liferay 7.4.

Enable input validation to ensure that only certain values are accepted in a Text or Numeric field.

Enabling Field Validation

To enable validation:

  1. While viewing a form, click on a Text, Numeric, or Date field to open the field configuration menu.

  2. Click the Advanced tab.

  3. Switch the Validation toggle to the right to enable validation.

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

Once validation has been enabled, configure the settings. For example, the Text field can specify the Accept If Input condition and the Error Message to indicate how validation failed.

The Field validation rule is triggered as soon as a User navigates away from a validated form field (by clicking into another field, for example).

Validation is triggered when the User leaves a validated field.

Validating Text Fields

See the Validation Conditions Reference for more information about the other validation conditions.

Validating Email Addresses

Forms can be configured to validate email addresses. To ensure that the user has entered a valid email address:

  1. Select the Is an email condition from the Accept If Input dropdown.

  2. Enter the error message in the Error Message field: Please enter a valid email address.

  3. Click Save when finished.

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

Validating URLs

Similar to emails, Forms can be configured to validate URLs.

To validate URLs:

  1. Select the Is a URL condition from the Accept If Input dropdown.
  2. Enter an error message.
  3. Click Save when finished.

Using Regular Expressions

Forms can be configured to use 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}$

To validate a text field using a regular expression:

  1. Select the Matches condition from the Accept If Input dropdown menu.

  2. Enter the regular expression.

  3. Enter an error message in the Error Message field.

    Regular expression text validation opens up countless possibilities.

  4. Click Save Form when finished.

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.

To validate numeric fields:

  1. Select the desired condition from the Accept If Input dropdown menu (for example, Is greater than).

  2. Enter numeric value (10) that serves as the limit.

  3. Enter an error message in the Show Error Message field.

    Numeric conditions constrain user-entered numeric data.

  4. Click Save Form when finished.

Requiring Only Integers

Forms can be configured to require numeric values to be integers. By default, the My numeric type is value is set to Decimal.

To configure the Numeric field to accept only integers:

  1. While viewing a form, click on a Numeric field to open the field configuration menu.

  2. On the Basic tab, click on the Integer radio button.

    Specify whether numbers can be decimals or integers only.

  3. Click Save Form to apply the changes.

Validating Date Fields

As of Liferay 7.4, the Advanced configuration of the Date Field includes Validation.

Enter validation rules for date fields.

Validation options include

Accepted Date: Require that the selected date be a future date, a past date, or a specified range.

Starts From/Ends On: In the case of future dates, define the date picker Start From date. For past dates, define the Ends On date. Configure whether the date picker should use the Response Date (the date that the user is filling out the form) or a custom date for this value. Both Starts From and Ends On must be configured for a date range validation.

Error Message: The error message can be customized to better suit the specific validation rule.

Masking Numeric Fields

The Input Mask configuration lets you you display the correct number format as the user enters numeric data. The configuration behavior differs between integer fields and decimal fields:

  • Integer field masks: configure the Format. A second entry, Character Options, is a read-only field setting that provides additional guidance on the character behavior used to define the format.

    Create an input mask for integer fields.

  • Decimal field masks: Configure the Thousands Separator, the Decimal Separator, the Decimal Places, and the Prefix or Suffix settings. The thousands separator style can be None, 1,000, 1.000, or 1 000. The decimal separator style can be 0.00 or 0,00. Prefix or Suffix. Use the Decimal Places setting to specify a limit to the number of decimal digits. The prefix or suffix is usually used to define the units of the decimal number. For example, use $ as a prefix for a field that expects the user to enter a dollar amount.

    Create an input mask for decimal fields.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy