From 7060fca89cc0d917c95d11346eabfc3e091a1aab Mon Sep 17 00:00:00 2001 From: Alfredo Delgado Date: Mon, 9 Apr 2018 16:55:58 -0400 Subject: [PATCH] Add numericality example with multiple custom messages. --- index.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/index.html b/index.html index cceb43d..747ee8a 100644 --- a/index.html +++ b/index.html @@ -1703,6 +1703,30 @@

Validators

validate({duration: "7"}, {duration: {numericality: {divisibleBy: 3}}}); // => {"duration": ["Duration must be divisible by 3"]} +var constraints = { + weight: { + numericality: { + notValid: 'is required', + greaterThan: 0, + notGreaterThan: 'must be greater than 0', + lessThan: 9999, + notLessThan: 'must be less than 9999' + } + } +}; + +validate({ weight: null }, constraints); +// => undefined + +validate({ weight: '' }, constraints); +// => { weight: [ 'Weight is required' ] } + +validate({ weight: 0 }, constraints); +// => { weight: [ 'Weight must be greater than 0.' ] } + +validate({ weight: 1000 }, constraints); +// => { weight: [ 'Weight must be less than 9999.' ] } + var constraints = { duration: { numericality: {