关于用户名textbox的验证
我想验证一个textbox。
条件是第一个字符必须是字母。而且不可少于五个字符。
我该怎么做??
问题点数:10、回复次数:3Top
1 楼Lcindep110(Descovering YourSelf)回复于 2006-03-01 19:56:53 得分 0
用正则......Top
2 楼lizi02(冬虫夏草)回复于 2006-03-01 21:36:39 得分 0
有很多实现方法啊
你可以用正则表达式,或者返回服务端处理,或者,重写一个验证控件,就是自己继承那些验证控件在做个组件.昨天刚刚看到的Top
3 楼apocaleaf()回复于 2006-03-02 08:56:54 得分 0
加一个ErrorProvider
this.errorProvider1.ContainerControl = this;
this.errorProvider1.SetIconAlignment(this.textBox1, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
this.errorProvider1.SetIconPadding(this.textBox1, 2);
然后在textBox1_Validated中textBox_TextChanged事件里写
if (char.IsLetter(this.textBox1.Text.ToCharArray()[0]) != true)
this.errorProvider1.SetError(this.textBox1, "首字母必须为字母");
else if (this.textBox1.Text.Length < 5)
this.errorProvider1.SetError(this.textBox1, "必需至少有5个字符");
不同的就是前者是textBox1失去焦点后验证,而后者是TextBox1每改变一次验证
Top




