Adding Validations to Clarity's Distributor Management App
So far, you've added various data fields to Clarity's distributor management app. Ensuring data integrity and consistency is the next crucial step for the application's success. In these exercises, you’ll add validations for email addresses, phone numbers, and URLs to improve Clarity’s distributor management app.
Exercise: Adding Validations for Email Address Fields
Liferay provides the isEmailAddress()
function for checking whether a field's value uses standard email address elements (e.g., @gmail, .com).
Here you’ll add validations for email address fields (i.e., applicantEmailAddress
).
-
Open the Global Menu (
), go to the Control Panel tab, and click Objects. -
Begin editing the Distributor Application object and go to the Validations tab.
-
Click Add (
), enter these details, and click Save.Field Value Label Email Address, applicantEmailAddress
Type Expression Builder
-
Begin editing the validation.
-
In the Basic Info tab, set these values:
Field Value Active Validation True Trigger Event On Submission
-
Go to the Conditions tab and enter these values:
Field Value Expression Builder isEmailAddress(applicantEmailAddress) OR applicantEmailAddress == ""
Error Message Please enter a valid applicant email address.
Error Message > Output Validation Type Full Validation (Form Summary)
This requires the field's value to follow a standard email address pattern or be empty. You can also use validations to make optional fields mandatory by not allowing users to leave the field empty.
If users attempt to submit an entry with an invalid value, Liferay displays the error message.
-
Click Save.
Exercise: Adding Validation for Phone Number Fields
Liferay provides the match()
function for checking whether the field's value matches a specified RegEx pattern or string value. In this scenario, Clarity wants to use this expression to validate their phone number fields: ^(\+\d{1,3} ?)?((\(\d{1,3}\))|\d{1,3})[- .]?\d{3,4}[- .]?\d{4}$
.
Here you’ll add validations for phone number fields (i.e., businessPhoneNumber
).
-
In the Validations tab, click Add (
), enter these details, and click Save.Field Value Label Phone Number, businessPhoneNumber
Type Expression Builder
-
Begin editing the newly created validation.
-
In the Basic Info tab, set these values:
Field Value Active Validation True Trigger Event On Submission
-
Go to the Conditions tab and enter these values:
Field Value Expression Builder match(businessPhoneNumber, "^(\+\d{1,3} ?)?((\(\d{1,3}\))|\d{1,3})[- .]?\d{3,4}[- .]?\d{4}$") OR businessPhoneNumber == ""
Error Message Please enter a valid business phone number.
Error Message > Output Validation Type Full Validation (Form Summary)
This validation supports a wide range of international phone numbers, allowing for international country codes, area codes, and separators. It also allows for format variations (e.g., spaces, dashes, dots), but enforces a minimum of 7 digits and a maximum of 11 digits. Since the field is optional, this validation also allows for empty values. -
Click Save.
Exercise: Adding Validation for Business Website Field
Liferay provides the isURL()
function for checking whether the field's value uses standard URL elements (e.g., http
, ://
, .com
).
Here you’ll add a validation for Clarity’s URL field (i.e., businessWebsiteURL
).
-
In the Validations tab, click Add (
), enter these details, and click Save.Field Value Label URL, businessWebsiteURL
Type Expression Builder
-
Begin editing the newly created validation.
-
In the Basic Info tab, set these values:
Field Value Active Validation True Trigger Event On Submission
-
Go to the Conditions tab and enter these values:
Field Value Expression Builder isURL(businessWebsiteURL) OR businessWebsiteURL == ""
Error Message Please enter a valid website URL.
Error Message > Output Validation Type Full Validation (Form Summary)
-
Click Save.
When finished, you should have three validations in total.
Since the validations are active, you can begin testing them.
Exercise: Testing the Validations
Here you’ll test your validations.
-
Open the Global Menu (
), go to the Applications tab, and click Distributor Application. -
Fill out the form, but ensure one of these fields uses an invalid value:
-
Applicant Email Address
-
Business Phone Number
-
Business Website URL
-
-
Click Save and verify the error message appears.
-
Fix the invalid value and click Save.
It should save successfully.
With these validations, Clarity can reduce errors, improve data integrity, and streamline the evaluation process.
Conclusion
Congratulations, you’ve added validations for business fields in Clarity’s distributor management app. By implementing these validations, Clarity can enforce data quality standards and maintain the accuracy and consistency of the data they collect. Next you’ll review what you’ve learned before moving on to the next module.
Capabilities
Product
Education
Contact Us