zoukankan      html  css  js  c++  java
  • C#的TextBox控件输入测试只允许输入数字的测试:

     

     

    代码如下: (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;
                    }
                }    
            }

  • 相关阅读:
    Handle/Body pattern(Wrapper pattern)
    Python: PS 滤镜--万花筒效果
    Java 工程与 Eclipse 高级用法
    更新服务
    Diskpart挂载/卸载VHD
    Ping批量函数
    Sysprep命令详解
    Hash Table构建
    Invoke-Express 执行多个批处理命令的函数
    磁盘扩容
  • 原文地址:https://www.cnblogs.com/twttafku/p/1131200.html
Copyright © 2011-2022 走看看