码迷,mamicode.com
首页 > 其他好文 > 详细

C# 中errorProvider控件的使用 和 正规表达式的使用

时间:2014-08-07 18:32:30      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   div   log   text   c#   

string strErrorMes = null;

if
(Validates()) { XXXXX } public bool Validates() { if (this.txtUserName.Text == "") { strErrorMes = "姓名不能为空!"; this.txtUserName.Focus(); errorProvider.SetError(this.txtUserName, strErrorMes); //给errorProvider控件赋值 } if (this.txtNativePlace.Text == "") { strErrorMes = "籍贯不能为空!"; this.txtNativePlace.Focus(); errorProvider.SetError(this.txtNativePlace, strErrorMes); //给errorProvider控件赋值 } if (this.txtphone.Text == "") { strErrorMes = "电话不能为空!"; this.txtphone.Focus(); errorProvider.SetError(this.txtphone, strErrorMes); //给errorProvider控件赋值 } else { string regStr = @"((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)"; bool isRightNo = Regex.IsMatch(txtphone.Text.Trim(), regStr); if (!isRightNo) { strErrorMes = "电话格式错误"; txtphone.Focus(); errorProvider.SetError(txtphone, strErrorMes); } } if (strErrorMes != null) {
              strErrorMes = null;

return false;
            }
            return true;
        }

 

C# 中errorProvider控件的使用 和 正规表达式的使用,布布扣,bubuko.com

C# 中errorProvider控件的使用 和 正规表达式的使用

标签:style   blog   color   使用   div   log   text   c#   

原文地址:http://www.cnblogs.com/zhangyonglvdaomei/p/3897433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!