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."
}