Skip to content

Commit 067a00e

Browse files
committed
Create the possibility to add steps in number
Like HTML5, we can use now steps for validaitng a number
1 parent 9a189f9 commit 067a00e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

form-validator/jquery.form-validator.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,9 @@
15291529
var allowing = $el.valAttr('allowing') || '',
15301530
decimalSeparator = $el.valAttr('decimal-separator') || conf.decimalSeparator,
15311531
allowsRange = false,
1532-
begin, end;
1532+
begin, end,
1533+
steps = $el.valAttr('step') || '',
1534+
allowsSteps = false;
15331535

15341536
if(allowing.indexOf('number') == -1)
15351537
allowing += ',number';
@@ -1544,6 +1546,11 @@
15441546
end = parseFloat(allowing.substring(allowing.indexOf(";")+1,allowing.indexOf("]")));
15451547
allowsRange = true;
15461548
}
1549+
1550+
if(steps != "")
1551+
{
1552+
allowsSteps = true;
1553+
}
15471554

15481555
if( decimalSeparator == ',' ) {
15491556
if( val.indexOf('.') > -1 ) {
@@ -1553,10 +1560,10 @@
15531560
val = val.replace(',', '.');
15541561
}
15551562

1556-
if(allowing.indexOf('number') > -1 && val.replace(/[0-9]/g, '') === '' && (!allowsRange || (val >= begin && val <= end)) ) {
1563+
if(allowing.indexOf('number') > -1 && val.replace(/[0-9]/g, '') === '' && (!allowsRange || (val >= begin && val <= end)) && (!allowsSteps || (val%steps == 0)) ) {
15571564
return true;
15581565
}
1559-
if(allowing.indexOf('float') > -1 && val.match(new RegExp('^([0-9]+)\\.([0-9]+)$')) !== null && (!allowsRange || (val >= begin && val <= end)) ) {
1566+
if(allowing.indexOf('float') > -1 && val.match(new RegExp('^([0-9]+)\\.([0-9]+)$')) !== null && (!allowsRange || (val >= begin && val <= end)) && (!allowsSteps || (val%steps == 0)) ) {
15601567
return true;
15611568
}
15621569
}

0 commit comments

Comments
 (0)