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

Commit 7060fca

Browse files
author
Alfredo Delgado
committed
Add numericality example with multiple custom messages.
1 parent 1fa5408 commit 7060fca

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,30 @@ <h2>Validators</h2>
17031703
validate({duration: "7"}, {duration: {numericality: {divisibleBy: 3}}});
17041704
// =&gt; {"duration": ["Duration must be divisible by 3"]}
17051705

1706+
var constraints = {
1707+
weight: {
1708+
numericality: {
1709+
notValid: 'is required',
1710+
greaterThan: 0,
1711+
notGreaterThan: 'must be greater than 0',
1712+
lessThan: 9999,
1713+
notLessThan: 'must be less than 9999'
1714+
}
1715+
}
1716+
};
1717+
1718+
validate({ weight: null }, constraints);
1719+
// =&gt; undefined
1720+
1721+
validate({ weight: '' }, constraints);
1722+
// =&gt; { weight: [ 'Weight is required' ] }
1723+
1724+
validate({ weight: 0 }, constraints);
1725+
// =&gt; { weight: [ 'Weight must be greater than 0.' ] }
1726+
1727+
validate({ weight: 1000 }, constraints);
1728+
// =&gt; { weight: [ 'Weight must be less than 9999.' ] }
1729+
17061730
var constraints = {
17071731
duration: {
17081732
numericality: {

0 commit comments

Comments
 (0)