需求:
1、一个TextBox控件,一个Button控件,当点击Button按钮时,判断TextBox中的内容是否为“空、I、N、P、i、n、p”如果不是,则弹出相应对话框。2、如果用户填写了“i、n、p”中的一个,在点击Button按钮存储数据时,将“i、n、p”转换为大写“I、N、P”。

解决方案 »

  1.   

    string s = TextBox.Text;
    Switch(s.ToUpper())
    {
     case "":
     case "I":
     case "N":
     case "P":
     TextBox.Text=s.ToUpper(); 
     default:
     MessageBox.Show("Error!");
    }
      

  2.   

    忘记了 break;
      

  3.   

    用if 或则case来判断一下么好了
      

  4.   

        var _text = document.getElementById('TextBox1').value.toUpperCase();
        if(_text == "" || _text == "I" ||_text == "N" ||_text == "P"){
           document.getElementById('TextBox1').value = _text;
        }else{
            alert("error");
        }
      

  5.   

            protected void Button1_Click(object sender, EventArgs e)
            {
                if (TextBox1.Text.Trim() == string.Empty || Checkstr(TextBox1.Text.Trim()) == false)
                {
                    RegisterStartupScript("", "<script>alert(\"输入不正确!\")</script>");
                }
                else
                {
                    RegisterStartupScript("", "<script>alert(\"输入字符为" + TextBox1.Text.Trim().ToUpper()+ "!\")</script>");
                }
            }
            public static bool Checkstr(string str)
            {
                return System.Text.RegularExpressions.Regex.IsMatch(str, @"^((I,N,P)|[i,n,p])?$");
            }
      

  6.   

    如果只能是“空、I、N、P、i、n、p”这些的话,正则表达式应该怎写?
      

  7.   


    return System.Text.RegularExpressions.Regex.IsMatch(str, @"^((I,N,P)|[i,n,p])*?$");