Question

4
Replies
4055
Views
pelln-1 Member since 2012 10 posts
PEGA
Posted: April 12, 2017
Last activity: April 28, 2017
Closed
Solved

How to add a custom edit validate rule and call it from the new harness

we have some fields that needs custom validation (like SSN as example) when the user enters input. The javascript function should be fired on an onchange event. Here are the steps i have followed.

1) Created the CustomValidators.js file in my ruleset. The code is mentioned below

<pega:when test='$SAVE(bClientValidation)=="true"'> <%-- include only when client validation is enabled --%>
<script>

***Moderator Edit: Vidyaranjan | Updated SR details & tagged SR Created***
var ruleEditValidate_ATA = new validation_ValidationType("ATACode", ATACode_Formatter);
ruleEditValidate_ATA.addEventFunction("onchange", ATACode_Formatter);

function ATACode_Formatter(object){
var format = "###-##-####";
if(object.value.length == 9){
dFilter(object,format);
}
return Format_Validation(object,format);
}

</script>
</pega:when>

2. The EDIT-VALIDATE rule is created for the ATACode as below

String ATACode = "^(\\d{3})-?\\d{2}-?\\d{4}$";

java.util.regex.Pattern p = java.util.regex.Pattern.compile(ATACode);

java.util.regex.Matcher m = p.matcher(theValue);

String[] strArr = theValue.split("-");

int numDashes = strArr.length - 1;

boolean isATA = m.matches();

if((isATA == false) || (numDashes == 0)){

return false;

}

if(theValue.length()!=11) {

return false;

}

return true;

. The harness should pick up this script. But it is not firing.

Any help is appreciated on how to incorporate custom edit validate rules. Also please let me know if a support request is required for this.

User Interface SR Created
Moderation Team has archived post
Share this page LinkedIn