asp.net后台cs文件对文本框进行数字校验

来源:互联网 发布:安卓看本子的软件 编辑:程序博客网 时间:2024/06/05 15:21



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;


namespace WebApplication1
{
    public partial class PersonInforPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label6.Text = "123456789903243563456534563456363466";
        }


        public static bool IsNumeric(string inputData)
        {
            Regex _isNumber = new Regex(@"^\d+$");
            Match m = _isNumber.Match(inputData);
            return m.Success;
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            string str = TextBox1.Text;


            if (IsNumeric(str))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "alert('是数字')", true);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "alert('不是数字')", true);
            }
        }


    }
}

0 0
原创粉丝点击