如果是DevExpress的控件有个Mark属性可以输入正则表达式来限定输入格式的。很好用

解决方案 »

  1.   

    先感谢1楼老兄,正则表达式~
    我是用VS2005 C#写WinForm
            private void txtUserID_TextChanged(object sender, EventArgs e)
            {
                if (txtUserID.Text.Length > 0)
                {
                    if (Encoding.Default.GetByteCount (txtUserID.Text) > 20)
                    {
                        int selIndex = txtUserID.SelectionStart;
                        int selLength = txtUserID.SelectionLength;
                        txtUserID.Text = txtUserID.Text.Substring(0, txtUserID.Text.Length - 1);
                        if (selIndex > txtUserID.Text.Length)
                        {
                            selIndex = txtUserID.Text.Length + 1;
                            selLength = 0;
                        }
                        else
                        {
                            if (selLength > txtUserID.Text.Length - selIndex)
                            {
                                selLength = txtUserID.Text.Length - selIndex;
                            }
                        }
                        txtUserID.SelectionStart = selIndex;
                        txtUserID.SelectionLength = selLength;
                    }
                }
            }
    只能想到这样,再具体、苛刻点怎么加工呢?
      

  2.   

    查了下,确实没用过,介绍也挺简单人性化的,但是Using跟引用是啥没有找到,照搬原样肯定报错。“网上能轻松查到”我也不必跟这里了是吧