求一个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"); }} 连接池的有无与Connection应静态与否的关系 DropDownList 求下载功能代码 vb调用webservice时,中文参数成乱码如何解决,急!!! 请问如何使richTextBox1充满整个窗口呢? 请问谁做过定位查找!当你没有输入一个字符的时候去查找,相同匹配。递归遍历!!! 关于文件操作问题如何删除其他线程正在读的文件 C#新手问题-相对路径-进度条 我新建一个线程,线程函数却没有执行。为什么? 请教: 想在C#里面弹出个窗口列出类似资源管理器左边那个树可以吗? 但我只想要“网上邻居”那一部分。 求助 正则表达式 在线等(急) 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");
}
}