In Pega can we validate the text a user types in a text box is a valid expression (like a formula or logical expression)

Hello,

we need to capture some input information from the user in the UI, it will be combination of some text, and data fields combination, for Ex: .pyAvailability= ‘always’ OR ‘within a defined time period’(Startdate<asoftoday && Enddate>asoftoday).

we need to validate either this is a valid expression or not. can we do it in pega?

Thanks,
Chandra Nelapati.

@Chandrababu

Yes, you can achieve this in Pega by configuring an Edit Validate rule for the property that holds the user input.

Edit Validate rule lets you write a custom Java function (inside a Rule-Utility-Function) to validate whether the string entered by the user is in the correct format (in your case, a valid formula/logical expression).

Once linked to the property, Pega will automatically invoke the validation whenever the user enters data in that text box.

If the input doesn’t match the expected expression syntax, Pega will display an error message on the UI.

But one thing is :

Pega doesn’t have an out-of-the-box expression parser for user-typed formulas. So the Edit Validate rule itself won’t magically understand logical expressions — you need to implement the parsing/validation logic (regex, token checks, or a custom parser) in the Java function you associate with the Edit Validate.

Hope this link will help :slight_smile:

@Chandrababu

don’t validate free-form “formulas” as raw text in Pega. Instead, give users a guided builder and validate each piece. Use a repeating list of clauses like [Field] [Operator] [Value] with AND/OR between rows, and restrict fields to a data page or picklist so they can’t type random names. On change of any clause, run a client-side validate (required fields, type checks) and a server-side validate (a When rule or activity) that tests each clause and the overall tree. On submit, translate the user’s choices into an actual When rule or a parameterized decision (Decision Table/Tree) rather than storing the text. If you must accept text, only allow a tiny grammar and gate it with an Edit Validate (regex) plus a server attempt to evaluate inside a try/catch, returning a friendly error. Log invalid tokens and block unsafe functions. This gives true validation, clear errors, and keeps the logic executable and maintainable.