javascript 仅禁用输入字段中的 .(DOT) 特殊字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31072376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:13:11 来源:igfitidea点击:
Disable only .(DOT) special charecter in input field
提问by Vijay Kumar
I don't want allow user to enter. (Dot) in my input field.. Rest of the required validation done already.
我不想让用户进入。(点)在我的输入字段中.. 其余所需的验证已经完成。
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
<input type="text" class="form-control" name="ContactNumber" maxlength="10" value="" id="ContactNumber" title="Enter Number Here" onkeypress="return isNumberKey(event)" required>