Legacy Knowledge Base
Published Jul. 2, 2025

Utilizing the Validation Feature Within the Web Form Portlet

Written By

Brett Ripley

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

This article contains a brief example for how to effectively manage validation in the web forms portlet.

Resolution

Note that following the below reproduction steps (or something similar) will produce an error:

  1. Deploy the Web Form portlet to a page
  2. Click on the wrench and select Configuration
  3. Create a new field
  4. Title the field Yes or No and change the type to radio buttons
  5. In the Options field enter Yes,No
  6. Click on Validation and in the Validation Script field enter return false;
  7. In the Validation Error Message enter False!
  8. Click Save
  9. Enter data on the form
  10. Click Submit

In the above scenario, the form is submitted without an error message that says “False!.

By default, validation is turned-off. To turn on validation, set validation.script.enabled=true in the portlet-ext.properties file, located in your Liferay Home directory

Example

This validation can be used in a variety of ways. Feel free to use the following scripts to verify phone numbers or email addresses.

Add a text field, and under the validation field enter the following script which will verify a nine digit number.

var regexObj = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

if (regexObj.test(currentFieldValue)) {

return true;

} else {

return false;

}

In order to verify that an email address has an @ and a period use the following script:

var isEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

if(currentFieldValue.search (isEmail) == -1 && currentFieldValue != '') {

return false;

} else {

return true;

}

Additional Information

Note that any code changes to the Web Form portlet for a specific environment are made at the developer's own discretion and are not supported by Liferay Subscription Services.

Creating Custom Validation Scripts on Web Form Portlet With DXP 7.0 

Did this article resolve your issue ?

Legacy Knowledge Base