Strict Mode
On this page
By default, the validator operates in “strict” mode. This means that the library expects you to define explicit validation rules for all properties within an object or keys within an array that you pass for validation. If a property/key lacks a corresponding rule, the library will throw an exception.
Purpose
Strict mode helps enforce data integrity and can prevent unexpected behavior. By requiring explicit validation, it encourages developers to think carefully about the expected format and constraints of the data they are handling.
Example (Strict Mode):
Disabling Strict Mode
If needed, you can disable strict mode by passing the strict: false
flag to the validate()
method. This allows you
to validate only the data for which you’ve explicitly provided rules, while ignoring other properties or array elements.
Example (Non-Strict Mode):
Use non-strict mode with caution. Always consider the data integrity requirements of your application.