文本框中的NAme验证 [英] NAme validation in a text box

查看:64
本文介绍了文本框中的NAme验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于输入name的文本框字段.现在,我要验证此文本框.我写下面的代码

I have a text box field used for enter name . Now I want to validate this text box . I write the code as below

Regex nm = new Regex(@"^[a-z A-Z]{2,120}$");
if (!nm.IsMatch(textBox2.Text))
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}



在C#.net



It doesn''t work correctly the coding is in C#.net

推荐答案

)中编码不正确. 如果(!nm.IsMatch(textBox2.Text)) { Message Box.Show(正确输入您的姓名",错误"); }
"); if (!nm.IsMatch(textBox2.Text)) { Message Box.Show("Enter Your Name Correctly ", "Error"); }



编码在C#.net中无法正常工作



It doesn''t work correctly the coding is in C#.net


尝试一下.

Try this.

Regex nm = new Regex(@"[a-z A-Z]{2,120}");
if (!nm.IsMatch(textBox2.Text))
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}







OR

Regex nm = new Regex(@"[a-z A-Z]{2,120}");
if (nm.Matches(textBox2.Text).Count == 0)
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}




如果有帮助,请 投票 接受答案 .




Please vote and Accept Answer if it Helped.


Regex nm = new Regex(@"^ [az AZ]");

现在使用它.
Regex nm = new Regex(@"^[a-z A-Z]");

Now use this.


这篇关于文本框中的NAme验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆