Applies to Pega Platform 7.2-8.5
Registering a custom validation
Important files for debugging validation errors
Specifying validations
Validation is a process of testing and ensuring that the user has entered required and properly formatted information through the web form. Validation rules not only ensure that incoming data is valid, but they also provide an additional layer of security. You can configure validation to occur either client side (if the data is being entered by a user) or server side (if the data is coming from an external system).
Client-side validation
Client-side validation occurs as a user is entering data into a browser. If a user enters data that is invalid or outside acceptable ranges, an error is raised that can be acted upon before the data enters the system.
In client-side validation, all the input validations and the error recovery process are carried out on the user’s browser. The browser performs the validation.
Client-side validation is triggered based on the event attached to validationtype.
Default validations that come with each control are as follows:
- Boolean, true-false
- Currency, decimal
- Date and Time, datetime
- Date, date
- Decimal, decimal
- Email, validemailaddress
- Integer, integer
- Percentage, decimal
- Phone, validphonenumber
- Time, timeofday
- URL, pxisvalidurl
Server-side validation
Server-side validation occurs when data has entered the system from any external source and cannot be validated beforehand. In this case, when invalid data is detected by a validation rule, an error is raised that marks the data as invalid. This can be detected and acted upon by other rule types to correct or notify someone about the error.
In server-side validation, all the input validations and error recovery process are carried out on the server side. The browser sends the request to the server to perform validations.
- Edit validate rules (Rule-Edit-Validate) handle Java code testing to check the validity of the input. Edit validate is associated to a particular property and validate value of the property on clipboard, if validation fails, Any commit of flow of execution does not forward. Some out-of-the-box controls might have equivalent client-side validation logic implemented, for example, email. Java code might be dependent on third-party libraries. Always try to run Java code separately to detect and resolve any ambiguity that might exist.
- Validate rules (Rule-Obj-Validate) evaluate general logical expressions. Validate rule is associated to an action (Flow action) and validates the assignment to be submitted. Functions used in building validate rules are evaluated at runtime. Evaluation is context-sensitive. Evaluation of the logical expression is triggered on Submit of a property value and stops processing if validation fails.
- Constraint validation rules for Declarative expressions (Rule-Declare-Constraints) run every time a property referenced in the constraint is changed. If a property in the clipboard fails the constraint, then an error message is added on the property. Because evaluation is performed every time a property changes, this might cause performance issues.
Registering a custom validation
1. Create an instance of validation type.
var numeric_decimal = new validation_ValidationType("decimal", numeric_isDecimal);
2. Add event listeners.
numeric_decimal.addEventFunction("onchange", numeric_isDecimal); numeric_decimal.addEventFunction("onblur", numeric_isDecimal);
3. Add implementation logic.
function numeric_isDecimal(){ //Logic goes here }
4. Add the implementation logic in an HTML fragment or a JS file and then add this to the harness scripts.
Important files for debugging validation errors
The pega_validators.js file contains validation logic for each validator registered.
The cs_valid.js file reads through every input field in the DOM, reads the validation type attribute, and invokes the actual validation logic that is present in the pega_validators file.
Standard client-side validation scripts are in the text file rule named webwb.CSValid.js. To allow for localization, the corresponding error messages are in the HTML fragment rule named CSValid. You can add custom client-side validation scripts or error messages application-wide by overriding the HTML fragment rule named UserWorkForm, which is included in the fragment WorkFormStandard, which in turn is included in the HTML code for every user form.
Common problems
The following table lists the commonly reported problems and how to prevent them:
Scenario | Explanation | Solution |
Validation message is lost on focusing in and out of the field. | Client-side validation invoked during refresh section removes the server-side validation. | Validation message is lost on focusing in and out of the field |
Validation messages do not display in read-only mode. | This is working as designed. The validation error displays depending on the configuration. That is, if the property is included directly in the grid or used in a section which is added as a section included in the grid. | Validation messages do not display in read-only mode |
Validation does not trigger for a label marked required. | A free form layout is implemented which is deprecated. Along with the label, the fields or control were not marked as required. | Pega Validation not triggered for a label marked required |
Error message flashes away on clicking outside the field. This occurs when there is a Required condition and Edit validate rule on a property. However, this works on click of tab, if the property is on a data page. | There is a server-side error or validation on a field along with client-side validations. If the client-side validations pass, the errors clear, even if the server-side error is present on the field. | Error message flashes away on clicking outside the field |
Validation error message displays with property names of the fields that caused the validation error. | This is working as designed. By default, Pega includes the property name of the field that the validation error occurred. | Validation error message displays property names |
Validation messages do not display when the control is in the Read-Only mode despite checking the 'Show validation messages in read-only mode' checkbox in the control. However, the message is present in the Clipboard. | Property value was used in the Value dropdown which was rendered in the Read-Only mode. This was considered as a label and validation was not added for the label. | Validation messages do not display in read-only mode fields |
Client-side validation does not work for Date fields on mobile device browsers. | When using the out-of-the-box Calendar control, the Pega application is in control of the HTML and Validation on the values entered. The application ensures that the onChange is triggered after client-side validations are enforced. When using the native Calendar control, the mobile operating system is in control of performing the basic Validation (for example, not entering random characters for the Date field). Once that is done, the operating system populates the control with the value and both the client-side validation and onChange are triggered almost simultaneously. Hence, the data transform receives the incorrect value. | Client side validation not working on mobile for date fields |
A mandatory field in a grid does not trigger an error if the value is empty. | This is working as designed. Required is a client-side validation, and the element that is not present in the UI does not trigger client-side validation. | Required error message does not display in the grid |
Validation is triggered for fields that are hidden based on the Visibility expression. | The Conditional expression for Required must be same as the Visibility expression. |
Configure Required conditionally to make an input control that is hidden based on a Visibility expression to be mandatory or Required, only when it displays on the form or screen. |
Related Content
Validating field values on a form