From 714bfe26f500bc5834a74d90eea7c65edda9cd70 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 2 Feb 2011 17:53:58 +0100 Subject: [PATCH] Functionality extensions. Two improvements. * add multiple decimal points (',' AND '.' may be declared), * accept '-' as the first character at any moment. --- numeric/jquery.numeric.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js index 0b179d2..b4249ec 100644 --- a/numeric/jquery.numeric.js +++ b/numeric/jquery.numeric.js @@ -59,9 +59,9 @@ $.fn.numeric.keypress = function(e) if(key < 48 || key > 57) { /* '-' only allowed at start */ - if(key == 45 && this.value.length == 0) return true; + if(key == 45 && $(this)[0].selectionStart == 0) return true; /* only one decimal separator allowed */ - if(decimal && key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1) + if(decimal && decimal.indexOf(String.fromCharCode(key)) > -1 && this.value.match(new RegExp('['+decimal+']'))) { allow = false; } @@ -139,4 +139,4 @@ $.fn.removeNumeric = function() return this.data("numeric.decimal", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).unbind("blur", $.fn.numeric.blur); } -})(jQuery); \ No newline at end of file +})(jQuery);