Validation Rules

In this section, we'll delve into the configuration of validation rules and constraints, focusing on the Form Validator's flexibility.

Validation Rules: The Heart of Form Validation

At the core of ReqEase's Form Validator lie validation rules and constraints. These rules define what constitutes valid input within your web forms. ReqEase provides two primary methods for configuring these rules:

1. Direct Field Validators

You can manually define validation rules by creating an array of fieldValidator objects. Each fieldValidator object includes two essential properties.

  • constraint: This refers to a constraint object, specifying a name and an array of validation rules.

  • field: The field property identifies the HTML or jQuery reference to the input element you want to validate.

Here's an example of a fieldValidator:

{
    constraint: {
        name: "username",
        length: {
            minimum: 6,
            maximum: 255,
        },
        /* rest of validation rules */
    },
    field: $("input[name='username1']")
}

Constraint is an object contains validation rules based on the library validate.js , check thier website for more custom validation rules.

This will be used by Form Validator in the validation process.

2. Using Constraints for Rule Building

ReqEase offers default constraints, pre-defined with common validation rules like 'username,' 'password,' and more. Additionally, you can define custom constraints, each with a unique name and an array of rules.

By strategically combining default and new constraints, you can automatically generate fieldValidators. The library searches for fields defined within constraints and pairs them with the associated rules. This approach is particularly useful when you want to set global options for your entire website, eliminating the need to manually define fieldValidators for common fields.

Validation Source: Configuring Rule Collection

The way validation rules are collected depends on the validationSource option in the Form Validator. There are two primary sources:

  • FULL (Default): In this mode, the constraints include both default constraints and new constraints. This results in fieldValidators being created based on both types of constraints. Use this when you want to combine predefined and custom rules.

  • ONLY_DEFINED: Here, the constraints exclusively consist of new constraints, omitting default constraints. FieldValidators are generated solely based on new constraints. Opt for this source if you wish to disregard default constraints and work exclusively with custom rules.

By understanding these rule configuration options, you gain fine-grained control over how validation is applied to your web forms in ReqEase. Whether you prefer to manually define fieldValidators or leverage constraints to automate the process, the library adapts to your specific needs.

Last updated