【发布时间】:2016-03-04 12:07:26
【问题描述】:
我想限制文本框中的十进制和字母值。我只想在文本框中输入数字。并且不要复制和粘贴文本和十进制值。不想只输入数字(0 o 9)。如何使用 javascript o jquery 的正则表达式来做到这一点。
看到这个小提琴,这里一切正常。但是方向键不起作用。我不能左右移动,如果我给出 (shift+home) 或 (shift + end) 它没有选择值。请帮帮我
$(".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>
这样做。
【问题讨论】:
标签: javascript jquery html regex