Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PropertiesComparisonRule

Validation rule that compares two object properties.

see

IValidationRule

Example

let schema = new ObjectSchema()
    .withRule(new PropertyComparisonRule("field1", "NE", "field2"));

schema.validate({ field1: 1, field2: 2 });       // Result: no errors
schema.validate({ field1: 1, field2: 1 });       // Result: field1 shall not be equal to field2
schema.validate({});                             // Result: no errors

Hierarchy

  • PropertiesComparisonRule

Implements

Index

Constructors

Methods

Constructors

constructor

  • Creates a new validation rule and sets its arguments.

    see

    ObjectComparator.compare

    Parameters

    • property1: string

      a name of the first property to compare.

    • operation: string

      a comparison operation: "==" ("=", "EQ"), "!= " ("<>", "NE"); "<"/">" ("LT"/"GT"), "<="/">=" ("LE"/"GE"); "LIKE".

    • property2: string

      a name of the second property to compare.

    Returns PropertiesComparisonRule

Methods

validate

  • Validates a given value against this rule.

    Parameters

    • path: string

      a dot notation path to the value.

    • schema: Schema

      a schema this rule is called from

    • value: any

      a value to be validated.

    • results: ValidationResult[]

      a list with validation results to add new results.

    Returns void

Generated using TypeDoc