Skip to content

Commit 71b3367

Browse files
author
mmsayed
committed
fix validating negative values with integer and float ranges
- return false if value is negative and negative is not allowd in "data-validation-allowing" attr - allow the "-" negative sign in regex matching for correct range checks
1 parent 2f76e31 commit 71b3367

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

form-validator/jquery.form-validator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,8 @@
15061506
if(allowing.indexOf('number') == -1)
15071507
allowing += ',number';
15081508

1509-
if(allowing.indexOf('negative') > -1 && val.indexOf('-') === 0) {
1510-
val = val.substr(1);
1509+
if(allowing.indexOf('negative') == -1 && val.indexOf('-') === 0) {
1510+
return false;
15111511
}
15121512

15131513
if (allowing.indexOf('range') > -1)
@@ -1528,10 +1528,10 @@
15281528
val = val.replace(',', '.');
15291529
}
15301530

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

0 commit comments

Comments
 (0)