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

Add numericality example with multiple custom messages. #265

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 10000 }, constraints);
// =&gt; { weight: [ 'Weight must be less than 9999.' ] }

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