zoukankan      html  css  js  c++  java
  • C# 中errorProvider控件的使用 和 正规表达式的使用

    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;
            }
  • 相关阅读:
    DS博客作业04--图
    DS博客作业03--树
    DS博客作业02--栈和队列
    DS01-线性表
    c博客06-结构体&文件
    C博客作业05--指针
    123
    面向对象设计大作业
    购物车
    有理数类的设计
  • 原文地址:https://www.cnblogs.com/zhangyonglvdaomei/p/3897433.html
Copyright © 2011-2022 走看看