Skip to content

Commit

Permalink
Create the possibility to add steps in number
Browse files Browse the repository at this point in the history
Like HTML5, we can use now steps for validaitng a number
  • Loading branch information
eleazan committed Aug 18, 2014
1 parent 9a189f9 commit 067a00e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions form-validator/jquery.form-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,9 @@
var allowing = $el.valAttr('allowing') || '',
decimalSeparator = $el.valAttr('decimal-separator') || conf.decimalSeparator,
allowsRange = false,
begin, end;
begin, end,
steps = $el.valAttr('step') || '',
allowsSteps = false;

if(allowing.indexOf('number') == -1)
allowing += ',number';
Expand All @@ -1544,6 +1546,11 @@
end = parseFloat(allowing.substring(allowing.indexOf(";")+1,allowing.indexOf("]")));
allowsRange = true;
}

if(steps != "")
{
allowsSteps = true;
}

if( decimalSeparator == ',' ) {
if( val.indexOf('.') > -1 ) {
Expand All @@ -1553,10 +1560,10 @@
val = val.replace(',', '.');
}

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

0 comments on commit 067a00e

Please sign in to comment.