Validate user input using errors and warnings

Validation of a rulebase is done in two ways: using error and warning events, and by specifying validations on user input. Validation will warn or prevent the user from entering values which do not meet certain criteria when running the rulebase.

Error and warning events are types of rules that specify an action to be taken in a process outside of the rulebase. They operate in a similar way to normal rules, except that instead of inferring a fact, they execute a command (ie firing the command specified in the conclusion line of the event rule). Event rules participate in inferencing only – not in the question search.

Oracle Policy Modeling also allows you to specify validations on the user input at runtime. These validations are set using minimum and maximum values and regular expressions on variable attributes. These input validations are triggered at the point which the value is submitted to the Engine and not during inferencing.

What do you want to do?

Write an error event rule

Write a warning event rule

Specify minimum and maximum values

Use regular expressions

Write an error event rule

An error event is used to pass a message to the user, and prevent them from continuing an investigation until the condition which triggered that error no longer applies.

To write an error event rule use the following syntax for the conclusion line of the rule:

 

For example,

Error("You can only be married to one person.") if

the applicant's number of spouses > 1

Write a warning event rule

A warning event is used to pass a message to the user, but permits them to continue despite the condition which triggered that warning.

To write a warning event rule use the following syntax for the conclusion line of the rule:

 

For example,

warning("The date of birth you have entered is in the future.") if

the person's date of birth > the current date

Specify minimum and maximum values

Minimum and maximum values can be specified for number, currency, date, time of day, and date/time variables to ensure that data entered by the user falls within a certain range. Values must be specified in the correct format.

To specify minimum and maximum values for an attribute: 

  1. Open the properties file for your project and double-click on the attribute in the Attribute view to open it in the Attribute Editor.
  2. Enter the minimum value in the Min value text field.
  3. Enter the maximum value in the Max value text field.
  4. Enter a message in the Error Message text field, to be displayed to the user when the validation is triggered, or leave the default error message (ie "Invalid Value").



  5. Click OK.

Use regular expressions

Regular expressions can be used in Oracle Policy Modeling to ensure that the data entered by the user matches an expected format. The main use for this is for text variables. Any regular expressions that include spaces and brackets can only be used on text variables (spaces and brackets are not valid input characters for number variables). Common regular expressions are given below:

 

Use Regular Expression
To check basic types of email addresses ^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$
To check the data entered follows a certain format: 2 letters 6 numbers 1 letter (eg AB123456C) ^[A-Za-z]{2}[0-9]{6}[A-Za-z]$
To check the data is a phone number in the format: (NN) NNNN NNNN where N = number. This example will match with or without the 2 spaces separating the sections. ^(\(0[0-9]\) ?[1-9][0-9]{3} ?[0-9]{4}$
To throw an error when the number of words in a text field exceeds a certain number where N is (the number of words permitted – 1) ^\s*(\S+(\s+\S+){0,N}\s*)?$
To check a National Insurance Number (NINO) ^[A-CEGHJ-PR-TWZ][A-CEGHJ-NPR-TWZ] ?\d{2} ?\d{2} ?\d{2} ?[ABCD]

 

TIP: There are a number of internet resources available on crafting regular expressions(eg http://en.wikipedia.org/wiki/Regex).

 

To specify a regular expression for an attribute: 

  1. Open the properties file for your project and double-click on the attribute in the Attribute view to open it in the Attribute Editor.
  2. Enter the regular expression in the RegExp text field.
  3. Enter a message in the Error Message text field, to be displayed to the user when the validation is triggered, or leave the default error message (ie "Invalid Value").
  4. Click OK.