More about Edit Validate rules
Use the Edit Validate form to define a Java routine that tests the validity of an input value in an activity that processes user input. The activity calls the Property-Validate method, which applies the test defined in an Edit Validate rule.
Cannot validate empty input fields
If an input field is blank, the edit validate rule associated with the property is not called. You can't create an edit validate rule that checks whether a value is empty.
Comparing edit validate and constraints rules
Constraints rules provide a useful alternative to edit validate rules, especially for properties that may be updated both by computations and by direct user input.
Comparing edit validate rules and edit input rules
Do not confuse edit validate processing with edit input processing:
- Edit input processing reformats user input for a property, whether or not the input is a valid value for the property.
- Edit validate processing operates after edit Input processing and never alters the property value.
- Edit input processing occurs automatically, as the system accepts user input and places it on the user's clipboard.
- Edit validate processing occurs only later, when an activity uses the Property-Validate method with that property or uses client-side format validation.
The property value (stored in the variable
theValue
) that is input to
edit validate processing may not be what the user typed, if an edit input transformation is
associated with the property.
Use of regular expressions
You can create edit validate rules that use regular expression pattern matching to validate user inputs. See the Pega Community article How to use regular expressions to validate user input.
Client-side validation
The standard text file rule named webwb.pega_validators.js includes JavaScript functions that exactly emulate standard edit validate rules. When enabled, these JavaScript functions are incorporated into user forms and flow actions, supporting client-side validation of user inputs, before a user submits the form.
You can build an edit validate rule in your application RuleSet that can perform the same function. JavaScript skills are required.
- Create and test your edit validate rule.
-
Associate the edit validate rule with a property.
- Open the rule form of a property.
- On the Advanced tab, under the Use Validate field, select the edit validate rule.
-
Create and test a JavaScript function that performs the same validation test as the edit validate rule, and has the same name. Follow the structure used in the standard text file rule webwb.pega_validators.js. For example, if you have associated the property with a IsNotFutureDateTest validate rule that checks if the date falls in the future, you need to create a JavaScript function by the same name such as:
/* IsNotFutureDateTest */
var ruleEditValidate_notFutureDateTest = new validation_ValidationType("notfuturedatetest", ruleEditValidate_isNotFutureDate);
ruleEditValidate_notFutureDateTest.addEventFunction("onchange", ruleEditValidate_isNotFutureDate);
- Save the JavaScript in a text file rule in your application RuleSet.
- Enable client-side validation by clicking the Enable Client Side Validation check box on the Advanced tab of the harness form. For best results use JSP tags and the SmartFrames format for the harness.
- Add the text file rule containing the JavaScript function on the Scripts and Styles tab of each harness that can present the field as an input field, that is, in read-write mode.
- Test your rule.
Message rule
When an input value fails validation by an edit validate rule, the system adds the message rule named PropertyInfo-EditValidate to the property. The default text is
Invalid value specified for {1}.
where {1} identifies the property.
You can view the generated Java code of a rule by clicking
. You can use this code to debug your application or to examine how rules are implemented.