Question
Atos
NL
Last activity: 22 Oct 2019 11:03 EDT
Email validation on property
Issue
Pega provides multiple email validations OOTB
Edit Validate rule: ValidEmailAddress
Function: pyServicesUtilities • pyValidateEmailID
Email validation on property
OOTB Edit Validate: ValidEmailAddress
null: true
name: false
name@: false
name@domain: true
Proprietary information hidden: true
Email validation via Validate rule
OOTB Function: pyServicesUtilities • pyValidateEmailID
[expression evaluates to true]
!@(Pega-IntegrationArchitect:pyServicesUtilities).pyValidateEmailID(.EmailProperty)
null: false
name: false
name@: false
name@domain: false
Proprietary information hidden: true
Using the regex java code of the Function(pyServicesUtilities • pyValidateEmailID) in the Edit Validate(ValidEmailAddress) should result in validation on property:
null: false
name: false
name@: false
name@domain: false
Proprietary information hidden: true
However, it results in:
null: true
name: false
name@: false
name@domain: true
Proprietary information hidden: true
***Edited by Moderator: Lochan to update platform capability tags***
Hi,
The OOTB 'ValidEmailAddress' validation rule will validate only the format " xxx@xxx "
We need to perform customization based on business requirement. I have tried the below customization at my end,
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;
Hi,
The OOTB 'ValidEmailAddress' validation rule will validate only the format " xxx@xxx "
We need to perform customization based on business requirement. I have tried the below customization at my end,
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 on-change event of the property outside the grid or add the below script in UserWorkForm,
<script>
var ruleEditValidate_validEmail = new validation_ValidationType("validMail", ruleEditValidate_isValidEmail);
ruleEditValidate_validEmail.addEventFunction("onchange", ruleEditValidate_isValidEmail);
function ruleEditValidate_isValidEmail(object) {
var x = pega.control.PlaceHolder.getValue(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.
When I use the above customization, it validates the email address and throws error if the entered value is not in the format " Proprietary information hidden "
Hope it helps!
Thanks,
Geeda.