Permalink
Browse files

Fixed issue #53 - number pattern failed when leading zero was left of…

…f decimal values.
  • Loading branch information...
1 parent 062cf08 commit 80c4fd0550c774324a476e6fb1fdfca2a7ba0b96 Eric Hamilton committed Oct 28, 2012
Showing with 33 additions and 3 deletions.
  1. +3 −0 .travis.yml
  2. +1 −1 jquery.h5validate.js
  3. +29 −2 test/test.h5validate.js
View
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - 0.8
View
@@ -33,7 +33,7 @@
url: /(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?/,
// Number, including positive, negative, and floating decimal. Credit: bassistance
- number: /-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?/,
+ number: /-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?/,
// Date in ISO format. Credit: bassistance
dateISO: /\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/,
View
@@ -189,8 +189,8 @@
test('Issue #44: validation throws an error when the number of characters in a textarea is > maxlength', function () {
- var $form = $('<form />')
- , $textarea = $('<textarea />').appendTo($form);
+ var $form = $('<form />'),
+ $textarea = $('<textarea />').appendTo($form);
$form
.appendTo('body')
@@ -211,6 +211,33 @@
ok(! $textarea.h5Validate('isValid'), 'Textareas with character length = ' + invalidLength + ' than maxlength = ' + maxlength + ' are invalid');
});
});
+
+ test('Issue #53 number pattern fails when leading zero is omitted ' +
+ 'from decimal value.', function () {
+ var $form = $('<form />'),
+ $num = $('<input type="text" class="h5-number" required="required"></input>')
+ .appendTo($form),
+ validValues = ['.3', '0.3', '9999999.9', '10', '-1', '-2.99'],
+ invalidValues = ['a', '2.x', 'x.2'];
+
+ $form
+ .appendTo('body')
+ .h5Validate();
+
+ validValues.forEach(function (num) {
+ $num.val(num).trigger('keyup');
+ ok($num.h5Validate('isValid'),
+ 'Valid number, ' + num +' should pass validation.');
+ });
+
+ invalidValues.forEach(function (num) {
+ $num.val(num).trigger('keyup');
+ ok(!$num.h5Validate('isValid'),
+ 'Invalid number, ' + num +' should not pass validation.');
+ });
+
+ $form.empty().remove();
+ });
}
exports.runTests = runTests;
}((typeof exports !== 'undefined') ? exports : window));

0 comments on commit 80c4fd0

Please sign in to comment.