MinLengthValidator

MinLengthValidator

Validates a variable which has a length property (e.g. a string) against the minimum length provided

MinLengthValidator is used by DataValidatorListener for validating data objects.

An attribute of a data model may define a min 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": {
        minLength:4
    }
}
 

An operation tries to save a data object:


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

Result:


 {
    "code": "EMINLEN",
    "model": "Product",
    "field": "model",
    "message": "The value is too short. It should have 4 characters or more."
}
 

Constructor

new MinLengthValidator(length)

Parameters:
Name Type Description
length number A number which represents the minimum length
Properties:
Name Type Description
minLength number Gets or sets an integer which represents the minimum length.
message string Gets or sets a string which represents a custom validator message.
Source:

Extends

Methods

getContext() → {DataContext|*}

Gets the current data context, if any.
Inherited From:
Source:
Returns:
Type
DataContext | *

setContext(context)

Sets the current data context.
Parameters:
Name Type Description
context DataContext | *
Inherited From:
Source:

validateSync(val) → {Object|undefined}

Validates the given value. If validation fails, the operation will return a validation result.
Parameters:
Name Type Description
val *
Source:
Returns:
Type
Object | undefined