判断输入的是否为汉字或者数字

利用控件的键盘按下事件:

 /// <summary>
       /// 判断是否按下数字键
       /// </summary>
        public static bool IsNumber(KeyPressEventArgs e)
        {
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (byte)(e.KeyChar) == 8)
            {
                return true;
            }
            else
            {
                e.Handled = true;
                return false;
            }
        }
 /// <summary>
       /// 判断输入是否为汉字
       /// </summary>
       /// <param name="e"></param>
        public static bool IsChinese(KeyPressEventArgs e, DevExpress.XtraEditors.TextEdit text)
        {
            if ((e.KeyChar >= (char)0x4e00) && (e.KeyChar <= (char)0x9fa5) || (byte)(e.KeyChar) == 8)
            {
                e.Handled = false;
                return true;
            }
            else
            {
                e.Handled = true;
                return false;
            }
        }



原文地址:https://www.cnblogs.com/dengshiwei/p/3971475.html