不允许使用标点符号,例如逗号或句号 [英] not allow punctuation like comma or periods
本文介绍了不允许使用标点符号,例如逗号或句号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我如何才能验证vb.net WINDOWS FORM中的文本框,以使其仅不允许两个标点字符,"和."
Hi ALL
How could i validate a textbox in vb.net WINDOWS FORM, so that it disallow only two punctuation character that is "," and "."
推荐答案
使用常规表达式验证器
如果唯一的约束是不允许标点符号,则不需要验证.最好从输入中过滤掉按键以忽略不想要的字符.为此:
1)处理TextBox.KeyPress
事件;
2)在事件处理程序中,从事件参数获取KeyChar
并弄清楚是否应将此字符过滤掉,在这种情况下,将事件参数的Handled
分配给true
.
3)方法char.IsPunctuation(char)
有助于对标点符号进行分类.
在发布此答案之前,我已经在代码中对其进行了测试.
—SA
If the only constraint is to disallow punctuation character, validation is not needed. It''s better to filter out key presses to ignore unwanted characters in first place, from input. For this purpose:
1) HandleTextBox.KeyPress
event;
2) In event handler, getKeyChar
from event argument and figure out if this character should be filtered out, in this case, assign event argument''sHandled
totrue
.
3) The methodchar.IsPunctuation(char)
helps to classify punctuation characters.
I tested it in code before posting this Answer.
—SA
这篇关于不允许使用标点符号,例如逗号或句号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文