方法一:

protected void btnTest_Click(object sender, EventArgs e)

    {
        string str = txtReg.Text.Trim();
        if (Regex.IsMatch(str, "^[0-9]*[1-9][0-9]*$"))
        {
            Response.Write("匹配");
        }
        else
        {
            Response.Write("不匹配");
        }
       
    }

using System.Text.RegularExpressions;

要引入正则的命名空间

方法二:前台验证方式:

<input   name=haha   onblur="if(!/^(\d|1[0-8])$/.test(this.value)){alert('错误');this.value=''}">

相关文章:

  • 2021-05-22
  • 2021-12-04
  • 2021-07-13
  • 2022-01-25
猜你喜欢
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-02-02
  • 2021-08-09
  • 2021-11-24
相关资源
相似解决方案