求一个TEXTBOX第一个字符的验证的代码 谢谢 窗体form1, 控件 一个textbox,一个button, 当用户在textbox中输入内容, 点击button后,如果textbox中的内容的第一个字符不是A或者B或者C 就弹出messegebox.show ("出错") 请问代码如何写啊;谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string fstr = textbox1.text.trim().substring(0,1);if(fstr!=A||fstr!=B||fstr!=C){ MessageBox.Show("出错") ;} string a = textBox1.Text.Substring(0, 1).ToUpper(); if (a == "A" || a == "B" || a == "C") { } else { MessageBox.Show("出错"); } <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Check();" /> function Check() { var va = document.getElementById("TextBox1").value; if (va) { var f = va.substring(0, 1); alert(f); if (f != "A" || f != "B" || f != "C") { alert("出错"); return false; } else { return true; } } else { return false; } } 当入为空时,肯定会报substring异常 C# codechar firstch = textbox1.text.trim()[0]if(fstr!='A'||fstr!='B'||fstr!='C'){MessageBox.Show("出错") ;} private void buttonX2_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length >= 1) { char firstch = textBox1.Text.Trim()[0]; if (firstch != 'A' || firstch != 'B' || firstch != 'C') { MessageBox.Show("出错"); } } } 用substring取第一个字符,判断就是了 if(txt1.Text!=""){ string a = txt1.Text.Substring(0, 1).ToUpper(); if (a != "A" || a != "B" || a != "C") { MessageBox.Show("Invalid input"); }} MenuItem.Header出错 应用程序内置浏览器,程序要绿色的,要怎么现实呢 判断文本框是否正在被编辑 请问如何在两个树控件之间画线(C#/Winforms) 【版务帖】2009年3月C#版务帖 C#连资料库后的字段问题 高手请进!!mshtml.HTMLWindow2Class强制转换的异常!! 如何使timer触发的频率再快些? 如何定义一个包含string的32bytes的结构类型? 请教:有关列表框 求助 正则表达式 在线等(急) WPF高手进
if(fstr!=A||fstr!=B||fstr!=C)
{
MessageBox.Show("出错") ;
}
if (a == "A" || a == "B" || a == "C")
{ }
else
{
MessageBox.Show("出错");
}
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1"
runat="server" Text="Button" OnClientClick="return Check();" /> function Check() {
var va = document.getElementById("TextBox1").value;
if (va) {
var f = va.substring(0, 1);
alert(f);
if (f != "A" || f != "B" || f != "C") {
alert("出错");
return false;
}
else {
return true;
}
}
else {
return false;
}
}
C# code
char firstch = textbox1.text.trim()[0]
if(fstr!='A'||fstr!='B'||fstr!='C')
{
MessageBox.Show("出错") ;
}
{
if (textBox1.Text.Trim().Length >= 1)
{
char firstch = textBox1.Text.Trim()[0];
if (firstch != 'A' || firstch != 'B' || firstch != 'C')
{
MessageBox.Show("出错");
}
} }
{
string a = txt1.Text.Substring(0, 1).ToUpper();
if (a != "A" || a != "B" || a != "C")
{
MessageBox.Show("Invalid input");
}
}