README
@validate.it/rules
Installation
// If you are using npm
npm install --save @validate.it/rules
// If you are using yarn
yarn add @validate.it/rules
Rule structure
Validation rules are JS objects containing a message
and a check
functions.
{
message: Function (attribute: string, options: Object),
check: Function (options: Object, ...args: any)
}
message
The message function defines the error message. It should return a String
and it receives the following parameters:
attribute <String>
: The name of the validated fieldoptions <Object>
: A object containing the rules options
check
This functions will validate the value. It should return a Boolean
(true
if passes, false
if fails) and receives the following parameters:
options <Object>
: Object containing the valaidation data:attribute <String>
: name of the field being validatedvalue <Any>
: value of the field being validateddata <Object>
: object containing all the fields being validated
...args <Any>
: the rest of the arguments are the validation rules options passed in order
Available rules
- accepted
- after
- afterOrEqual
- alpha
- alphaDash
- alphaNum
- array
- before
- beforeOrEqual
- between
- boolean
- confirmed
- date
- dateEquals
- dateFormat
- different
- digits
- digitsBetween
- distinct
- greaterThan
- greaterThanOrEqual
- image
- in
- inArray
- integer
- ip
- ipv4
- ipv6
- json
- lessThan
- lessThanOrEqual
- max
- mimetypes
- mimes
- min
- notIn
- notRegex
- nullable
- numeric
- present
- regex
- required
- requiredIf
- requiredUnless
- requiredWith
- requiredWithAll
- requiredWithout
- requiredWithoutAll
- same
- size
- string
- url
Version log
v0.0.x:
- Initial commits
- Created first rules