代码如下: (VS2005)

       public TextBoxInputCheck(object sender, KeyPressEventArgs e,INPUTTYPE type)
       {
            if(type == INPUTTYPE.INT)
            {
                string pattern = @"^[0-9]";
                Regex reg = new Regex(pattern);
                if ((!reg.Match(e.KeyChar.ToString()).Success) && (e.KeyChar.ToString() != ""))
                {
                    e.Handled = true;
                }
            }
            else if(type == INPUTTYPE.FLT)
            {
                string pattern = @"^[0-9]|.$";
                Regex reg = new Regex(pattern);
                if ((!reg.Match(e.KeyChar.ToString()).Success) && (e.KeyChar.ToString() != ""))
                {
                    e.Handled = true;
                }
                else if (e.KeyChar.ToString() == "." && (sender as TextBox).Text.IndexOf('.') > 0)
                {
                    e.Handled = true;
                }
            }    
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-05-25
  • 2021-11-24
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
相关资源
相似解决方案