Validators - agentg2007/validation-context GitHub Wiki
Custom Validator
You can create your own custom validator.
const TextIsNotFooBarValidator = (value:any, oldValue:any, params:any) => {
return ({
valid: value != "FooBar",
message: "Value contains FooBar"
})
}
Default Validators
You can use built-in validators included in the package.
RequiredFieldValidator
This validator is used to make an input control required.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Value Required!" |
type | Values are string, number, datetime, boolean, list, or just leave it blank. If type is set to string, it will check for null or empty (trimmed) value. If type is number, it will check if it has a number value. If the type datetime checks for a valid date value. If type is boolean, it checks for a true/checked value. If type is list, it checks if the value is an array and has at least 1 value inside. | null |
NumberInputFieldValidator
This validator is used to ensure input value is number.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Value must be a number!" |
NumberRangeFieldValidator
This validator evaluates the value of an input control to check that the value lies between specified ranges.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Invalid value range!" |
min | Minimum number of the range. | −9007199254740991 |
max | Maximum number of the range. | 9007199254740991 |
DateTimeRangeFieldValidator
This validator evaluates the value of an input control to check that the date value lies between specified ranges.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Invalid date range value!" |
min | Minimum datetim of the range. | "01/01/1900, 12:00:00 AM" |
max | Maximum datetime of the range. | "01/31/100000, 12:00:00 AM" |
EmailFieldValidator
This validator evaluates the value of input control value is a valid email address.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Invalid email value!" |
UrlFieldValidator
This validator evaluates the value of input control value is a valid url address.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Invalid url value!" |
StringLengthFieldValidator
This validator evaluates the value of an input control to check that the string value length lies between specified ranges.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Invalid character count!" |
min | Minimum characters to check. | 0 |
max | Maximum characters to check. | 9007199254740991 |
SelectedItemCountFieldValidator
This validator evaluates the value of an input control to check that the number of selected items count lies between specified ranges.
Parameter | Description | Default Value |
---|---|---|
message | Message to display on validation message. | "Please select at least ${min} items." |
min | Minimum items to check. | 1 |
max | Maximum items to check. | 9007199254740991 |