用于特殊字符验证的javascript代码 [英] javascript code for special character validation
本文介绍了用于特殊字符验证的javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我需要一个JavaScript代码,不允许使用特殊字符和数字,并允许
我的文本框中的空格
在此先感谢
afsal
Hi All
i need a javascript code for not allowing special characters and numbers and allow
spaces in my text box
thanks in advance
afsal
推荐答案
本文包含一个小型JS框架,其中包含您需要的内容.还有更多类似性质的东西.
用于常见验证场景的微型Javascript框架. [ ^ ]
P.S.只需将AcceptAlphabetOnly
函数的参数用作true
即可.
This article contains a small JS framework which contains what you need. also many more of similar nature.
A Tiny Javascript Framework for Common Validation Scenarios.[^]
P.S. just use theAcceptAlphabetOnly
function with argument for spaces astrue
.
这是一个类似的简单示例:
以下是过滤方法:
This is a simple sample of similar thing:
Here is how to filter out:
<html>
<head>
<script type="text/javascript"><!--
function filterDigits(eventInstance) {
eventInstance = eventInstance || window.event;
key = eventInstance.keyCode || eventInstance.which;
if ((47 < key) && (key < 58) || key = 45 || key == 8) {
return true;
} else {
if (eventInstance.preventDefault) eventInstance.preventDefault();
eventInstance.returnValue = false;
return false;
} //if
} //filterDigits
--></script>
</head>
<body">
<input type="text" onkeypress="filterDigits(event)"/>
</body>
</html>
请注意,允许使用键码8(退格键).由于某些历史原因,此键被视为字符,因此应特别允许通过过滤器.
Pay attention that the key code 8 (backspace) is allowed. By some historical reason, this key is considered as a character, so it should be specifically allowed through the filter.
这篇关于用于特殊字符验证的javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文