gpt4 book ai didi

javascript - 如何验证 html 文本框不允许特殊字符和空格?

转载 作者:太空狗 更新时间:2023-10-29 15:22:52 24 4
gpt4 key购买 nike

这是我的 html:

 <input type="text" name="folderName">

在这里,我想通过不允许键入特殊字符和空格来验证文本框值。但它应该允许下划线。

如何验证这个文本框?

最佳答案

你可以尝试使用这个功能:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function blockSpecialChar(e){
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
</script>
</head>
<body>
<form id="frm" runat="server">
<input type="text" name="folderName" onkeypress="return blockSpecialChar(event)"/>
</form>
</body>
</html>

关于javascript - 如何验证 html 文本框不允许特殊字符和空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24774367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com