Pattern vs Expression

Options
Kevin_579059
Kevin_579059 Posts: 67
edited May 2020 in Questions

Hello,
I am a little confused between the entry validations of Pattern and Expression.

It seems if you want to use a Regex, you need to use Pattern. This seems counter-intuitive because Regex is short for regular expression.
Is Pattern mainly used for when you are just checking the characters entered against the available characters on the keyboard?
And is Expression there to check the entries entered against fields, etc.
Is there some overlap between the two?
thanks!
Kevin

Answers

  • Brandon_189578
    Options

    Kevin,

    You are correct. Expression is a generalized term that basically means something that can be evaluated into a value. In our context of validation, the expression needs to return a true or false value to indicate whether the data entered matches the requirements.

    Pattern is a specific subtype of an expression (a regular expression, as you pointed out). It will only allow you to test validity against a regular expression. Pattern validation is good if the constraint you want to apply to the field can be easily converted into a regular expression.

    If that cannot be done, or as you noted, you need to reference other fields to determine validity, that is when an Expression validation is more useful. It allows you to have more precise control over what the data should be without being restricted by the syntax and constraints of regular expressions, as well as letting you reference field data that is not known at the time of the expression being written.