rules library
The builder functions of all built-in rules, to compose rules of your own.
Functions
-
anyObject(
List< Object?> args, RuleContext context) → LivrRule -
any_object: the value must be an object (aMap). Its content is not validated. -
decimal(
List< Object?> args, RuleContext context) → LivrRule -
decimal: the value must be a number, an integer or a decimal. Strings are accepted in the form-12or-12.34, and the output is always adouble. -
defaultValue(
List< Object?> args, RuleContext context) → LivrRule -
default: sets the value when it is empty: missing,nullor an empty string. Other values,0included, are kept. -
email(
List< Object?> args, RuleContext context) → LivrRule -
email: the value must be an email address. -
eq(
List< Object?> args, RuleContext context) → LivrRule -
eq: the value must be equal to the argument. Values are compared as strings, and the output is the argument. -
equalToField(
List< Object?> args, RuleContext context) → LivrRule -
equal_to_field: the value must be equal to the value of another field. Values are compared as strings:'10'and10are equal. A missing field is not equal to any value. -
integer(
List< Object?> args, RuleContext context) → LivrRule -
integer: the value must be an integer. Strings with an integer ('10','1e3') are accepted, and the output is always anint. -
isoDate(
List< Object?> args, RuleContext context) → LivrRule -
iso_date: the value must be an ISO 8601 date without time, like2014-08-14. -
leaveOnly(
List< Object?> args, RuleContext context) → LivrRule -
leave_only: Removes all characters except the given ones. Numbers and booleans are converted to strings, objects and lists are left as they are. -
lengthBetween(
List< Object?> args, RuleContext context) → LivrRule -
length_between: the string must have frommintomaxcharacters (Unicode code points), inclusive. The output is the value as a string. -
lengthEqual(
List< Object?> args, RuleContext context) → LivrRule -
length_equal: the string must have exactly the given number of characters (Unicode code points). The output is the value as a string. -
like(
List< Object?> args, RuleContext context) → LivrRule -
like: the value must match the regular expression. Flags are the second argument:{like: ['^[a-z]+$', 'i']}; onlyi(ignore case) is supported. The output is the value as a string. -
listOf(
List< Object?> args, RuleContext context) → LivrRule -
list_of: validates every element of a list with the same rules. Errors are a list with the error of every element,nullfor valid elements. Both the new syntax{list_of: ['required', 'email']}and the old one{list_of: [['required', 'email']]}work. -
listOfDifferentObjects(
List< Object?> args, RuleContext context) → LivrRule -
list_of_different_objects: validates every element of a list with one of several object schemas. The value of the selector field of an element chooses the schema, like invariable_object. -
listOfObjects(
List< Object?> args, RuleContext context) → LivrRule -
list_of_objects: validates every element of a list with the same object schema. Errors are a list with the errors of every element,nullfor valid elements. -
maxLength(
List< Object?> args, RuleContext context) → LivrRule -
max_length: the string must have at most the given number of characters (Unicode code points). The output is the value as a string. -
maxNumber(
List< Object?> args, RuleContext context) → LivrRule -
max_number: the number must be at most the argument. Strings with a number are accepted, and the output is the number. -
minLength(
List< Object?> args, RuleContext context) → LivrRule -
min_length: the string must have at least the given number of characters (Unicode code points). The output is the value as a string. -
minNumber(
List< Object?> args, RuleContext context) → LivrRule -
min_number: the number must be at least the argument. Strings with a number are accepted, and the output is the number. -
nestedObject(
List< Object?> args, RuleContext context) → LivrRule -
nested_object: validates a nested object with its own schema. Errors have the shape of the object. -
notEmpty(
List< Object?> args, RuleContext context) → LivrRule -
not_empty: the value must not be an empty string, if it is present. -
notEmptyList(
List< Object?> args, RuleContext context) → LivrRule -
not_empty_list: the value must be a list with at least one element. -
numberBetween(
List< Object?> args, RuleContext context) → LivrRule -
number_between: the number must be frommintomax, inclusive. Strings with a number are accepted, and the output is the number. -
oneOf(
List< Object?> args, RuleContext context) → LivrRule -
one_of: the value must be one of the arguments. Values are compared as strings, and the output is the allowed value. Both the new syntax{one_of: ['a', 'b']}and the old one{one_of: [['a', 'b']]}work. -
or(
List< Object?> args, RuleContext context) → LivrRule -
or: applies the sets of rules one after another until one of them succeeds:{or: ['email', 'positive_integer']}. When all of them fail, the error of the last one is returned. -
positiveDecimal(
List< Object?> args, RuleContext context) → LivrRule -
positive_decimal: the value must be a number greater than zero. Strings are accepted in the form12or12.34, and the output is always adouble. -
positiveInteger(
List< Object?> args, RuleContext context) → LivrRule -
positive_integer: the value must be an integer greater than zero. Strings with an integer are accepted, and the output is always anint. -
remove(
List< Object?> args, RuleContext context) → LivrRule -
remove: Removes the given characters from the string. Numbers and booleans are converted to strings, objects and lists are left as they are. -
required(
List< Object?> args, RuleContext context) → LivrRule -
required: the value must be present, notnulland not an empty string.0andfalseare valid values. -
string(
List< Object?> args, RuleContext context) → LivrRule -
string: the value must be a primitive value, it is converted to a string. -
toLc(
List< Object?> args, RuleContext context) → LivrRule -
to_lc: Converts the string to lower case. Numbers and booleans are converted to strings, objects and lists are left as they are. -
toUc(
List< Object?> args, RuleContext context) → LivrRule -
to_uc: Converts the string to upper case. Numbers and booleans are converted to strings, objects and lists are left as they are. -
trim(
List< Object?> args, RuleContext context) → LivrRule -
trim: Removes leading and trailing whitespace. Numbers and booleans are converted to strings, objects and lists are left as they are. -
url(
List< Object?> args, RuleContext context) → LivrRule -
url: the value must be an http or https URL, with the protocol. -
variableObject(
List< Object?> args, RuleContext context) → LivrRule -
variable_object: validates an object with one of several schemas. The value of the selector field chooses the schema:{variable_object: ['type', {'material': {...}, 'service': {...}}]}.