• C# 字符、字符串过滤,只能输入数字、中文、英文、大写、小写(转)


    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;

            }

     原文地址:

  • 相关阅读:
    Codeforces 868A Bark to Unlock
    poj 3744 Scout (Another) YYF I
    Codeforces 526F Pudding Monsters
    Codeforces 789D Weird journey
    Codeforces 827E Rusty String
    Codeforces 841D Leha and another game about graph
    bzoj 3560 DZY Loves Math V
    Codeforces 833A The Meaningless Game
    Codeforces 839D Winter is here
    Codeforces 839C Journey
  • 原文地址:https://www.cnblogs.com/Godblessyou/p/2286623.html
Copyright © 2020-2023  润新知