I have a textbox called count. I want to enter only positive and negative numbers in the textbox using JavaScript or jQuery regular expression. Do not allow "text" and "decimals" and "special characters" in the textbox. Even copy and paste also it should take only positive or negative numbers.
Important:
If I copy and paste text or decimal or special character also it should not take. It should take only positive or negative numbers.
I want to enter and paste negative values without decimal.
Arrow keys should work.
Shift, Ctrl, Home, End, Enter like this buttons also should work.
Please check the following fiddle and please modify this.
$(".allownumericwithoutdecimal").on("keypress keyup blur",function (event) {
$(this).val($(this).val().replace(/[^\d].+/, ""));
if ((event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
<span>Int</span>
<input type="text" name="numeric" class='allownumericwithoutdecimal'>
<div>Numeric values only allowed (Without Decimal Point) </div>
I am new for regex. Please help me for do this.
+sign allowed for positive numbers ?