String rules
String rules accept primitive values: strings, numbers and booleans. Numbers are validated as strings. All of them return FORMAT_ERROR for objects and lists.
stringChecks that the value is a primitive type and converts it to a string, for example 25 becomes "25". Prefer stricter rules where possible.'string'FORMAT_ERROReqChecks that the value is equal to the given one. Values are compared as strings, and the output is the value from the rule.{ eq: 'Anton' }NOT_ALLOWED_VALUEone_ofChecks that the value is one of the allowed values. Values are compared as strings, and the output is the value from the rule.{ one_of: ['a', 'b'] }NOT_ALLOWED_VALUEmax_lengthChecks that the string is not longer than the given number of characters.{ max_length: 10 }TOO_LONGmin_lengthChecks that the string is at least the given number of characters long.{ min_length: 2 }TOO_SHORTlength_betweenChecks that the length of the string is between the two values, inclusive.{ length_between: [2, 10] }TOO_LONGTOO_SHORTlength_equalChecks that the string is exactly the given number of characters long.{ length_equal: 2 }TOO_LONGTOO_SHORTlikeChecks that the value matches a regular expression.{ like: '^[0-9]+$' }WRONG_FORMATnot_one_of2.5Checks that the value is not equal to any of the given values. Values are compared as strings, and the output is the value unchanged.{ not_one_of: ['admin', 'root'] }NOT_ALLOWED_VALUEdigits2.5Checks that the value consists of ASCII digits 0-9 only. Unlike positive_integer, leading zeros are kept and the output is a string.'digits'NOT_DIGITSstarts_with2.5Checks that the value starts with one of the given strings.{ starts_with: 'https://' }WRONG_FORMATends_with2.5Checks that the value ends with one of the given strings.{ ends_with: '.pdf' }WRONG_FORMATcontains2.5Checks that the value contains at least one of the given strings.{ contains: '@' }WRONG_FORMAT