此处使用 jQuery,但无法阻止在输入字段中输入数字
http://codepen.io/leongaban/pen/owbjg http://codepen.io/leongaban/pen/owbjg
Input
<input type="text" name="field" maxlength="8"
title="Only Letters"
value="Type Letters Only"
onkeydown="return alphaOnly(event);"
onblur="if (this.value == '') {this.value = 'Type Letters Only';}"
onfocus="if (this.value == 'Type Letters Only') {this.value = '';}"/>
jQuery
function alphaOnly(event) {
alert(event);
var key;
if (window.event) {
key = window.event.key;
} else if (e) {
key = e.which;
}
//var key = window.event.key || event.key;
alert(key.value);
return ((key >= 65 && key <= 90) || (key >= 95 && key <= 122));
}
我在这里看到了很多关于如何仅限于数字的示例,并且我对 a-z 和 A-Z 使用了正确的键代码。你看到我做错了什么了吗?
短内衬:
<input onkeydown="return /[a-z]/i.test(event.key)" >
For all 统一码字母 https://www.regular-expressions.info/unicode.html#category尝试这个regexp https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp: /\p{L}/u
(but https://stackoverflow.com/a/52205643/860099 ... this https://stackoverflow.com/a/37668315/860099) - 这是工作示例 https://jsfiddle.net/0autqd4b/3/ :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)