Skip to content
Roman Samec edited this page Jul 26, 2014 · 7 revisions

Validation engine

To participate in enterprise business process, employees, customers and partners need to interact with data stored in various enterprise applications – whether providing information or retrieving it. These stored data are typically structured data or semi-structured data that must correspond to specific business rules or validation rules.

Validation engine offers a way how to define business rules of the product, the contract, or to define validation rules of the forms that captures this data.

Validation engine advantages

The main benefit is that validation engine is not tight to HTML DOM or any other UI framework. This validation engine is UI agnostic and that is why it can be used as an independent representation of business rules of a product, contract, etc. It can be easily reused by different types of applications, libraries.

  • It enables to decorate custom objects and its properties with validation rules.
  • It supports composition of validation rules, that enables to validate custom object with nested structures.
  • It is ease to create your own custom validators.
  • It supports asynchronous validation rules (uses promises).
  • It supports assigning validation rules to collection-based structures - arrays and lists.
  • It supports localization of error messages with TranslateArgs.
  • It deploys as AMD, CommonJS or plain script module pattern.
  • It offers basic build-in constrains validators. Other custom validators can be find in extensible repository of custom validators.

Typical usage of validation engine can be:

  • Client - server validation of business rules for an product.
    • UI application uses validation engine to enforce all validation rules with quick answer to client.
    • Server non-UI application uses the same business rules to enforce validity of business rules of the product once again (according to rule no client is trusted).
  • Validation of business rules of automatically generated products, contracts, etc.
    • Server non-UI application can automatically generate the product or the contract. Validation engine enforce validation of business rules of the product, the contract, etc.
  • Forms application which uses business rules to capture structured or semi-structured data.

Types of validators and validation rules

  • Custom property validator
  • Custom object validator
    • with property validation rules (sync and async)
    • with collection-valued, array-valued and generally Iterable fields and properties
    • with shared validation rules
  • Composite object validator

Dependencies

The validation is not dependend on HTML DOM. The only depedency is on ECMAScript.

Temporary there is dependency on the underscore, moment and Q javacript libraries.

There can be other dependencies on other javascript libraries for custom validation rules found in repository of custom validators.

Before using any custom validator found in repository, check the api for the custom validator for possible dependencies. E.g. DataCompareValidator requires underscore + moment javascript libraries.

List of basic property validators

The Property validator is designed to validate objects against constraints. They are assertions that a condition is true.

Basic constrains

  • Required
  • EqualTo

String constrains

  • Email
  • Url
  • MaxLength,MinLength,RangeLength
  • Pattern

Number constrains

  • Number
  • Digits, SignedDigits
  • Max,Min,Range
  • Step

Date constrains

  • Date
  • DateISO
  • DateCompare

Financial and other Number Constraints

  • Currency
  • CreditCard
  • Luhn

Collection constraints

  • Contains

Localization

It supports localization of constrains messages. See the list of available localization messages in i18n directory.

Localization is enabled by default. It is enough to add reference to specific localization files. For Czech Republic localization add reference to dist/localization/messages_cs.js to html page where you want to use CZ messages.