sat*_*mar 2 html javascript regex jquery
我想在文本框中重写小数和alphabatic值.我只想在文本框中输入数字.并且不要复制和粘贴文本和十进制值.只想输入数字(0 o 9).我怎么能用javascript的jgeery正则表达式做到这一点.
看到这个小提琴,这里一切正常.但箭头键不起作用.我无法向左和向右移动,如果我给(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();
}
});Run Code Online (Sandbox Code Playgroud)
<span>Int</span>
<input type="text" name="numeric" class='allownumericwithoutdecimal'>
<div>Numeric values only allowed (Without Decimal Point) </div> Run Code Online (Sandbox Code Playgroud)
做这个.
$(".allownumericwithoutdecimal").on("keypress keyup blur paste", function(event) {
var that = this;
//paste event
if (event.type === "paste") {
setTimeout(function() {
$(that).val($(that).val().replace(/[^\d].+/, ""));
}, 100);
} else {
if (event.which < 48 || event.which > 57) {
event.preventDefault();
} else {
$(this).val($(this).val().replace(/[^\d].+/, ""));
}
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<span>Int</span>
<input type="text" name="numeric" class='allownumericwithoutdecimal'>
<div>Numeric values only allowed (Without Decimal Point) </div>Run Code Online (Sandbox Code Playgroud)