Posts

Showing posts from January, 2022

Server-side validation using Edit Validate rules

Image
Let's start with a short tutorial to see how server-side validation works using Edit Validate rules. Create the MobilePhone Edit Validate rule with the following Java Source: // ************************** // // Edit Validate: MobilePhone // // ************************** // java.util.regex.Pattern regex = java.util.regex.Pattern.compile("^[0-9]{9}$", java.util.regex.Pattern.CASE_INSENSITIVE); java.util.regex.Matcher matcher = regex.matcher(theValue); if (!matcher.find()) { theProperty.addMessage("[server] The phone is invalid"); return false; } return true; Create the .Phone property and set its "Use validate" option to MobilePhone . Create the EmailAddress Edit Validate rule with the following Java Source: // *************************** // // Edit Validate: EmailAddress // // *************************** // java.util.regex.Pattern regex = java.util.regex.Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", java....

How does Pega perform client-side validation

Image
This is the second post in the series about client-side validation in Pega. In the previous post, we've learned about the ValidationError object. In this post we will describe the steps made by the "Submit" button when we click on it. Also, we will introduce the ValidationType objects and the Validation functions . These elements are the building blocks of client-side validation in Pega so we will need to know their role when implementing it. We will study ValidationType objects and validation functions that already exist, so we will not create custom ones, that will be the subject of the next post. Before we start... Let's create the MobilePhone Edit Validate rule with the following definition. // Edit Validate: MobilePhone if (theValue.length() != 9) { theProperty.addMessage("The entered value must be 9 digits long"); return false; } else if ( !(theValue.startsWith("8") || theValue.startsWith("9")) ) { theProperty...

Display error messages in HTML fields

Image
In this post we will learn how to display and clean up error messages in the HTML fields of a Pega form manually using JavaScript. This post is part of a bigger one in which we will create custom client-side validations, and since that post was getting too big I decided to split it into small posts (divide and conquer!) The "ValidationError" object The ValidationError object just contains an error message and a reference to the HTML element to attach the error message. We can create a ValidationError object using the validation_Error constructor which is defined in the csvalid.js text file rule. // Creates a new ValidationError object var errorObj = new validation_Error(elementHTML, "Hello World!"); Display a ValidationError object Creating a ValidationError object is not sufficient for it to be displayed in the user interface. We can display the ValidationError object manually using the display_addImageError function which is defined i...