diff --git a/numericInput.js b/numericInput.js index dd69880..90228f1 100644 --- a/numericInput.js +++ b/numericInput.js @@ -29,7 +29,7 @@ var min = settings.min; var max = settings.max; - if(min == max) + if(min !== undefined && max !== undefined && min == max) { throw("The minimum value cannot be the same as the max value"); } @@ -59,7 +59,7 @@ else if (allowNegative == true && inputCode == 45) // Conditions for a decimal point { - if(currentValue.charAt(0) == '-') + if(currentValue.charAt(0) == '-' && getSelectEnd(this) == 0) return false; if(getCaret(this) != 0) @@ -75,7 +75,7 @@ else if(inputCode > 0 && (inputCode >= 48 && inputCode <= 57)) // Disallows numbers before a negative. { - if (allowNegative == true && currentValue.charAt(0) == '-' && getCaret(this) == 0) + if (allowNegative == true && currentValue.charAt(0) == '-' && getCaret(this) == 0 && getSelectEnd(this) == 0) return false; } }); @@ -133,4 +133,12 @@ return 0; }; + + function getSelectEnd(element) + { + if (element.selectionEnd) + return element.selectionEnd; + else + return 0; + } }( jQuery ));