相忘于江湖

不抛弃,不放弃... 请给我勇敢,改变可以改变的;请给我坚强,接受不可以改变的;请给我智慧,分辨这两者。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)     //文本框输入字符过滤
        {
           
            if (Convert.ToInt32(e.KeyChar) >= 48 && Convert.ToInt32(e.KeyChar) < 58 ||          //包括数字
                //(Convert.ToInt32(e.KeyChar) >= 65 && Convert.ToInt32(e.KeyChar) < 91) ||        //包括大写字母
                //(Convert.ToInt32(e.KeyChar) >= 97 && Convert.ToInt32(e.KeyChar) < 123) ||       //包括小写字母
                //(Convert.ToInt32(e.KeyChar) == 46) ||                                           //包括.
                //(Convert.ToInt32(e.KeyChar) == 32) ||                                           //包括空格
                //(Convert.ToInt32(e.KeyChar) == 64) ||                                           //包括@
                //(Convert.ToInt32(e.KeyChar) > 127) ||                                           //包括中文
                Convert.ToInt32(e.KeyChar) == 8)                                                //包括退格
            {

            }
            else
            {
                e.Handled = true;
            }


public static bool ReplaceCodes(String Temp)       //检查字符串过滤方法
        {

            string s = Temp;
            int l = s.Length;
            char[] buf = s.ToCharArray();
            string tmp = string.Empty;
            for (int k = 0; k < buf.Length; k++)
            {
                if ((Convert.ToInt32(buf[k]) >= 48 && Convert.ToInt32(buf[k]) < 58))//||        //数字
                //(Convert.ToInt32(buf[k]) >= 65 && Convert.ToInt32(buf[k]) < 91) ||            //大写字母
                //(Convert.ToInt32(buf[k]) >= 97 && Convert.ToInt32(buf[k]) < 123) ||           //小写字母
                //(Convert.ToInt32(buf[k]) == 46) ||                                            //.
                //(Convert.ToInt32(buf[k]) == 32) ||                                            //空格
                //(Convert.ToInt32(buf[k]) == 64) ||                                            //@
                //(Convert.ToInt32(buf[k]) > 127) ||                                            //中文
                //(Convert.ToInt32(buf[k]) == 8))                                               //退格
                {
                    tmp += buf[k].ToString();

                }
            }
            if (tmp.Length != l)
            {
               // Util.info("请输入正确整数数字!");
                //Temp = tmp; 
                return false;
            }
            else
                return true;

        }

 

 原文地址:

posted on 2011-12-13 18:09  playman0211  阅读(682)  评论(0编辑  收藏  举报