Validations Types and Constraints
Less than to read
The provided table summarizes different validation types and constraints available in the Sage 200 Web Amendability Schema.
Validation Types and Constraints
String
Type | Constraints | Parameters | Description |
---|---|---|---|
string | required | message | Requires the value to be present. |
length | value, message | Checks the length of the string. The ${length} interpolation can be used in the message argument | |
min | value, message | Checks if the string length is at least a minimum. The ${min} interpolation can be used in the message argument | |
max | value, message | Checks if the string length is at most a maximum. The ${max} interpolation can be used in the message argument | |
message | Validates email format. | ||
matches | value, message | Checks if the string matches a regular expression. You must pass your RegEx to the value property as a schema string object, else the string will be considered a reference to the value of another field - e.g. for three groups of one or more capital letters, separated by - , use { "string": { "value": "^([A-Z])+-([A-Z])+-([A-Z])+$" } } The Sage 200 Web Portal uses JavaScript Regular Expressions, which may differ from those used in your Visual Basic and C# code. Read more information on JavaScript Regular Expressions at MDN. |
|
url | message | Validates URL format. | |
ensure | message | Ensures the value is a string. | |
trim | message | Trims whitespace from the string. | |
lowercase | message | Converts the string to lowercase. | |
uppercase | message | Converts the string to uppercase. |
In addition, supports all the same Constraints as mixed.
Number
Type | Constraints | Parameters | Description |
---|---|---|---|
number | min | value, message | Checks if the number is greater than or equal to a min. The ${min} interpolation can be used in the message argument. |
max | value, message | Checks if the number is less than or equal to a max. The ${max} interpolation can be used in the message argument. | |
lessThan | value, message | Checks if the number is less than a max. The ${less} interpolation can be used in the message argument. | |
moreThan | value, message | Checks if the number is more than a min. The ${more} interpolation can be used in the message argument. | |
positive | message | Checks if the number is positive. | |
negative | message | Checks if the number is negative. | |
integer | message | Checks if the number is an integer. | |
truncate | Truncates the decimal part of the number. |
In addition, supports all the same Constraints as mixed.
Date
Type | Constraints | Parameters | Description |
---|---|---|---|
date | min | value, message | Checks if the date is after or equal to a min date. When a string is provided it will attempt to cast to a date first and use the result as the limit. |
max | value, message | Checks if the date is before or equal to a max date. When a string is provided it will attempt to cast to a date first and use the result as the limit. | |
nullable | Allows the date field to be left blank. If you’ve set the “allowEmptyValue” property to true, it’s essential to include the “nullable” constraint in validation. Without it, clearing the date field may trigger validation errors. |
In addition, supports all the same Constraints as mixed.
Array
Type | Constraints | Parameters | Description |
---|---|---|---|
array | required | message | Requires the array to be non-empty. |
min | value, message | Checks if the array length is at least a min. | |
max | value, message | Checks if the array length is at most a max. | |
ensure | message | Ensures the value is an array. |
In addition, supports all the same Constraints as mixed.
Object
Type | Constraints | Parameters | Description |
---|---|---|---|
object | camelCase | Validates camel case naming for keys. | |
constantCase | Validates constant case naming for keys. |
In addition, supports all the same Constraints as mixed.
Boolean
In addition, supports all the same Constraints as mixed.
Mixed
Type | Constraints | Parameters | Description |
---|---|---|---|
mixed | clone | Creates a deep copy of the schema. Clone is used internally to return a new schema with every schema state change. | |
oneOf | arrayOfValues, message | Checks if value is one of specified values. | |
notOneOf | arrayOfValues, message | Checks if value is not one of specified values. | |
strict | Sets whether strict mode is enabled. | ||
label | label: string | Assigns a label to the schema. | |
describe | Collects schema details (like meta, labels, and active tests) into a serializable description object. | ||
isType | value | Runs a type check against the passed in value. It returns true if it matches, it does not cast the value. | |
default | value | Sets a default value to use when the value is undefined. Defaults are created after transformations are executed, but before validations, to help ensure that safe defaults are specified. The default value will be cloned on each use, which can incur performance penalty for objects and arrays. | |
default | Calling default with no arguments will return the current default value | ||
nullable | isNullable: boolean | Sets whether the value can be null. | |
required | message | Requires the value to be present. | |
notRequired | Removes the requirement for the value to be present. | ||
defined | Marks the schema as defined, allowing undefined values. | ||
typeError | message | Sets a custom error message for type mismatch. |