VB.Net 验证:检查文本是否仅包含字母 [英] VB.Net Validation: Checking if Text Contains Only Letters
本文介绍了VB.Net 验证:检查文本是否仅包含字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要知道如何验证文本框的文本以确保它只包含没有空格的字母.
Need to know how to validate a Text Box's text to make sure it contains ONLY letters without spaces.
我希望存在某种可以帮助我的函数,例如IsString"之类的.
I was hoping some sort of functions exists which could help me, something like "IsString" or something.
推荐答案
使用 正则表达式一个>
if System.Text.RegularExpressions.Regex.IsMatch(TextBox.Text, "^[A-Za-z]+$")) ...
编辑
^ $
字符是锚;它们分别表示匹配 start 和 end-of-line,可用于防止子字符串/部分匹配.
The ^ $
character are anchors; they mean match the start and end-of-line respectively and can be used to prevent sub-string/partial matches.
例如正则表达式 X
将匹配 "X"
和 "AAAXAAA"
但 ^X$
只匹配 "X"
作为它的值可以认为是 "
E.g. The regex X
would match "X"
and "AAAXAAA"
but ^X$
only matches "X"
as its value can be thought of as "<start of line>X<end of line>"
这篇关于VB.Net 验证:检查文本是否仅包含字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文