Utilizing the Validation Feature Within the Web Form Portlet

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


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


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 

0 人中有 0 人觉得有帮助