Support Article
Email address validation rule does not work in a table layout
Summary
In Pega Platform 8.1.5, the following issues occur:
Issue 1: In the email address, the out-of-the-box Edit Validate rule validates only abc@ xyz and not [email protected]
Issue 2: The Email address Validation error message does not diplay in the table layout.
Error Messages
Not Applicable
Steps to Reproduce
- Create an Email property and use the out-of-the-box 'ValidEmailAddress' Validation rule. At runtime, the email validates only abc@ xyz and not [email protected]
- Add the email property in a table. The error messages display as a tooltip.
Root Cause
The out-of-the-box 'ValidEmailAddress' validation rule validates only abc@ xyz.
Customization must be performed based on the user's requirement. Additionally, the email address Validation error message not diplaying in the table layout and appearing as a tooltip is working as per Pega product design.
Resolution
Perform the following local-change:
For Issue 1:
- Create a EditValidate rule with the below code,
if (theValue == null || theValue.trim().equals("")) return false;
try {
javax.mail.internet.InternetAddress emailAddr = new javax.mail.internet.InternetAddress(theValue);
emailAddr.validate();
}
catch (javax.mail.internet.AddressException ex){
return false;
}
if(theValue.contains("."))
return true;
theProperty.addMessage("Enter a Valid Email Address");
return false;
- For client side validation, use 'Post Value' for onchange event of the property outside the grid or add the below script in UserWorkForm,
<script>
var x = pega.control.PlaceHolder.getValue(object);
var ruleEditValidate_validEmail = new validation_ValidationType("validMail", ruleEditValidate_isValidEmail);
ruleEditValidate_validEmail.addEventFunction("onchange", ruleEditValidate_isValidEmail);
function ruleEditValidate_isValidEmail(object) {
if (null == x || "" == x) {
return;
}
// Regular expression for email address
// RFC822 regular expression
var emailReg = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]+$/;
var validMail = emailReg.test(x);
if (!validMail) {
return display_getValidationError(object, ruleEditValidate_isValidEmailAddressMsgStr, "", true);
}
}
</script>
Note: ValidMail (Mentioned in above script) is the custom Edit Validate rule created. The above script is required to validate the property inside the grid.
For Issue 2:
For the error message to display in the grid, include the Email property control in a section in the grid Cell properties.
Published August 15, 2019 - Updated December 2, 2021
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.