Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Add numericality example with multiple custom messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfredo Delgado committed Apr 24, 2018
1 parent 1fa5408 commit 7060fca
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,30 @@ <h2>Validators</h2>
validate({duration: "7"}, {duration: {numericality: {divisibleBy: 3}}});
// =&gt; {"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);
// =&gt; undefined

validate({ weight: '' }, constraints);
// =&gt; { weight: [ 'Weight is required' ] }

validate({ weight: 0 }, constraints);
// =&gt; { weight: [ 'Weight must be greater than 0.' ] }

validate({ weight: 1000 }, constraints);
// =&gt; { weight: [ 'Weight must be less than 9999.' ] }

var constraints = {
duration: {
numericality: {
Expand Down

0 comments on commit 7060fca

Please sign in to comment.