如果输入不应在文本框中显示,则仅输入字符数和特殊字符 [英] enter only characters numbers and special char not allowed if entered should not display in text box
本文介绍了如果输入不应在文本框中显示,则仅输入字符数和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在开展一个项目,其中有一个申请表,我只想输入字符(a-z,A-Z)。不允许使用数字和特殊字符。允许使用空格。如果输入数字,则不应在文本框中显示,以便任何人都可以帮助我。?
Hello,
I am working on a project in which there is a application form in which I want to enter only characters(a-z,A-Z). Numbers and special characters are not allowed. White space is allowed.If number is entered it should not display in text-box so anyone can help me.??
推荐答案
本文介绍了如何完成此操作。实际上有一个可重用的js文件,可以包含在任何项目中并与其一起使用以实现这个以及许多其他常见的验证和过滤方案。
一个简单的Javascript框架,用于常见验证方案。 [ ^ ]
This article shows how this can be done. In fact there is a reusable js file that can be included and used with any project to achieve this and many other common validation and filtration scenarios.
A Tiny Javascript Framework for Common Validation Scenarios.[^]
有很多方法可以做到这一点。
你可以使用正则表达式模式,验证器控件或只是简单的按键处理来实现这些结果。
简单的关键事件处理示例 -
There are a number of ways to do this.
You can use regex patterns, validator controls or just plain key down handling to achieve these results.
Simple key event handling example -
private void txtInputNo_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = (char.IsCharacter(e.KeyChar) || char.IsSpecial(e.KeyChar);
}
IsCharacter
和 IsSpecial
方法检查输入字符是否为两者之一。
The IsCharacter
and IsSpecial
methods check if the input character is either of the two.
您可以使用正则表达式验证javascript中输入的文本。 />
希望这些链接可以帮助您
http:/ /www.advanced-javascript-tutorial.com/RegularExpressions.cfm#.UVqS10O6a1s [ ^ ]
你的正则表达式可以是这样的
var reSSN = / ^ [A-Za-z0-9]
You can use regular expression to validate the entered text in javascript.
Hope these links may help you
http://www.advanced-javascript-tutorial.com/RegularExpressions.cfm#.UVqS10O6a1s[^]
your regular expression can be like this
var reSSN = /^[A-Za-z0-9 ]
这篇关于如果输入不应在文本框中显示,则仅输入字符数和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文