From 4621ee02361530707ce5d8c3f819978411e2adcd Mon Sep 17 00:00:00 2001 From: peter royal Date: Tue, 8 Feb 2011 15:50:39 -0500 Subject: [PATCH 1/2] user can enter negative number if whole value is selected --- numeric/jquery.numeric.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js index 0b179d2..c1f8da0 100644 --- a/numeric/jquery.numeric.js +++ b/numeric/jquery.numeric.js @@ -3,7 +3,7 @@ * Copyright (c) 2006-2010 Sam Collett (http://www.texotela.co.uk) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. - * + * * Version 1.2 * Demo: http://www.texotela.co.uk/code/jquery/numeric/ * @@ -59,7 +59,7 @@ $.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.value.length == 0 || (this.selectionEnd - this.selectionStart) == this.value.length)) return true; /* only one decimal separator allowed */ if(decimal && key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1) { From 3a5650e289b082fe3fe3659997bfb4de86947a6f Mon Sep 17 00:00:00 2001 From: Oleg Sidorkin Date: Wed, 2 Mar 2016 16:30:53 +0300 Subject: [PATCH 2/2] Update jquery.numeric.js Allow negative inputs --- numeric/jquery.numeric.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js index c1f8da0..7477772 100644 --- a/numeric/jquery.numeric.js +++ b/numeric/jquery.numeric.js @@ -126,7 +126,7 @@ $.fn.numeric.blur = function() var val = $(this).val(); if(val != "") { - var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+"); + var re = new RegExp("^-?\\d+$|\\d*" + decimal + "\\d+"); if(!re.exec(val)) { callback.apply(this); @@ -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);