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

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

 /// <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;
            }
        }



 

posted @ 2014-07-08 17:05  静以养身 俭以养德  阅读(205)  评论(0编辑  收藏  举报