用于文本框验证的正则表达式 [英] Regex for textbox validation
本文介绍了用于文本框验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Windows窗体上使用Textbox控件接受由逗号分隔的字母数字字符串。我尝试了一些,但没有满足需要。
例如文本框应该能够接受以下输入 -
002312,1221,XA112X12,ASADSD
< b>我尝试了什么:
我尝试使用这个正则表达式来更新我需要但却无法更新的内容。
^ [az] +(?:,[az] +)* $
这是我在测试时现在要验证的方式。
匹配m = Regex.Match(txtRegex.Text,@ ^ [AZ] +(:,[AZ] +)* $);
if(m.Success)
{
//根据需要进一步处理
}
else
{
txtRegex.Focus();
}
解决方案
这是我在测试时现在要验证的方式。
匹配m = Regex.Match(txtRegex.Text,@^ [az] + (?:,[AZ] +)*
);
if(m.Success)
{
//根据需要进一步处理
}
else
{
txtRegex.Focus();
}
空白......
尝试:
^ \w +(?:[,\s] * \w +)*
I need to have Textbox control on windows form accepting alphanumeric strings which are separated by a comma. I tried some but did not meet the need.
e.g. Textbox should be able to accept below as input -
002312, 1221,XA112X12, ASADSD
What I have tried:
I tried this regular expression to update what I need but was not able to.
^[a-z]+(?:,[a-z]+)*$
This is how I will be validaing for now while testing.
Match m = Regex.Match(txtRegex.Text, @"^[a-z]+(?:,[a-z]+)*$"); if (m.Success) { //process futher as needed } else { txtRegex.Focus(); }
解决方案
This is how I will be validaing for now while testing.
Match m = Regex.Match(txtRegex.Text, @"^[a-z]+(?:,[a-z]+)*
"); if (m.Success) { //process futher as needed } else { txtRegex.Focus(); }
Whitespace...
Try:
^\w+(?:[,\s]*\w+)*
这篇关于用于文本框验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文