-
Notifications
You must be signed in to change notification settings - Fork 1
Home
- Do we need sometimes to specify validators order? Should we break validation chain if some validation fails?
- validators should not depend on their order
====
- Whether to validate the empty/not exists values and values are not a suitable type?
-
Empty/not_exists - valid, incorrect type - valid
➕ validators become simpler
➕ most of validators return one type of message
➕ you don't need to duplicate type or empty validation in every validator
➕ order of validators doesn't important
➖ you need to combine validators in application. In fact type validator becomes mandatory in most situations
➖ you can miss values of incorrect type as valid- Angular 2:
if (isPresent(Validators.required(control))) return null;
. e.g. number + minLength validator = valid
- Angular 2:
-
Empty/not_exists - valid, incorrect type - converts to correct type
[🗸]
➕ validators become simpler
➕ most of validators return one type of message
➕ you don't need to duplicate type or empty validation in every validator
➕ order of validators doesn't important
➖ you need to combine validators in application. In fact type validator becomes mandatory in most situations
➖ you can miss values of incorrect type as valid, but it will be not important for reducible types- Angular 1:
minlength = toInt(value) || 0; ctrl.$isEmpty(viewValue) || viewValue.length >= minlength;
- ZF2 validator if setAllowEmpty=true (Converts string to number)
- Simfony 2 validator. Throw exception if type is not convertible
- Angular 1:
-
Empty/not_exists - valid, incorrect type - invalid
➕ one validator for many common situations
➕ you never miss incorrect type values
➖ validators become complex
➖ validators have duplicated logic and messages
➖ validators likelength
return error 'must be a string or an array', but generally you have specific type and you need specific error (f.e. 'must be a string'). That is why you need specialstring
validator before- Validate.js:
if (v.isEmpty(value)) { return; } if(!v.isNumber(length)) { return "has an incorrect length"; }
- Ruby on Rails validator if allow_blank, allow_nil are true
- Java Bean validator (null element is valid for many validators)
- Validate.js:
-
Empty/not_exists - invalid, incorrect type - invalid
➕ one validator for many common situations
➕ you never miss empty or incorrect type values
➖ validators become complex
➖ validators have duplicated logic and messages
➖ you need to set extra flag for validate values which can be an empty
➖ validators likelength
return error 'must be a string or an array', but generally you have specific type and you need specific error (f.e. 'must be a string'). That is why you need specialstring
validator before- Ruby on Rails validator by default
- ZF2 validator by default
====
- How to validate incorrect type/empty values in other validators (use this.validatorName or [validator1, validator2] format)
- both ways
====
- What should be the strict (==/===) default setting for min, max, equal etc. validators?
- no strict. You can set type if you need strict checking
====
- Behavior of required type validators
undefined | null | NaN | true | false | 0/ "0" | 1 | ""/ " " | {} | [] | |
---|---|---|---|---|---|---|---|---|---|---|
required | • | • | • | • | ||||||
notEmpty | • | • | • | • | • |
JSON.stringify(NaN) === "null"
JSON.stringify(new Date('foo')) === "null"
-
notEmpty
is useful for PATCH-requests - for
0
checking more logical to use min-validator - in other cases you can use type-checking
====
- Which validators should be in library and What should be validator names and params?
Common
- custom
- validate
- required | presence
- notEmpty
Types
- object
- array
- number
- integer
- string
- date
- boolean
- null
- function
- type
Equality (valid if value is empty)
- equal (strict)
- confirm (strict)
Numbers (valid if value is not number or empty)
- max (inclusive=true)
- min (inclusive=true)
- range (from, to, inclusive=true, fromInclusive=true, toInclusive=true)
- odd
- even
- divisible
Length (valid if value is not string or not array or empty, inclusive flag isn't necessary because length is integer)
- maxLength
- minLength
- rangeLength
- equalLength
RegExp (valid if value is not string or empty)
- pattern | format
White and black list (valid if value is empty)
- inclusion
- exclusion
Date and time (valid if value is not valid date)
- maxDateTime
- minDateTime
- rangeDateTime
- equalDateTime
- maxDate
- minDate
- rangeDate
- equalDate
Web (valid if value is not string or empty)
- url (allowLocal, protocol)
====
-
What should be compared value name?
-
rule ?
-
comparedValue
-
arg
[🗸]
-
argument
-
target
эталон
- standard
- model
- etalon
- gage
- sample
- master form
- base
критерий
- criterion
- canon
- yardstick
- norm
- test
- benchmark
ограничение
- limitation
- restriction
- constraint
- restraint
- curb
шаблон
- templet
- mask