PatternValidator

most-data/data-validator~ PatternValidator

Validates a variable against the regular expression provided

PatternValidator is used by DataValidatorListener for validating data objects.

An attribute of a data model may define a max length in validation properties:


     {
        "name": "model",
        "title": "Model",
        "description": "The model of the product. Use with the URL of a ProductModel or a textual representation of the model identifier. The URL of the ProductModel can be from an external source. It is recommended to additionally provide strong product identifiers via the gtin8/gtin13/gtin14 and mpn properties.",
        "type": "Text",
        "validation": {
            "pattern":"^[A-Z]{2}\\.\\d{3}$",
            "patternMessage":"Product model seems to be invalid. Valid values are VC.100, DX.010 etc."
        }
    }
     

An operation tries to save a data object:


     var obj = {
                "model": "FS240098701",
                "name": "USB 3.0 Adapter"
            };
     context.model("Product").save(obj).then(function() {
               return done();
           }).catch(function(err) {
               return done(err);
           });
     

and the result is:


     {
        "code": "EPATTERN",
        "model": "Product",
        "field": "model",
        "message": "Product model seems to be invalid. Valid values are VC.100, DX.010 etc."
    }
     

Constructor

new PatternValidator(pattern)

Parameters:
Name Type Description
pattern string A string which represents a regular expression
Properties:
Name Type Description
message string Gets or sets a string which represents a custom validator message.
Source:

Extends

  • DataValidator

Methods

validateSync(val) → {Object|undefined}

Validates the given value and returns a validation result or undefined if the specified value is invalid
Parameters:
Name Type Description
val
Source:
Returns:
Type
Object | undefined