110,499
社区成员
发帖
与我相关
我的任务
分享
Boolean flag1 = true;
Boolean flag2 = true;
Boolean flag3 = true;
String str = this.txtSerialNo.Text;//输入的字符
String strsub1, strsub2;
strsub1 = str.Substring(0,6);//前6位
strsub2 = str.Substring(6,0);//7
//MessageBox.Show("sub1=" + strsub1);
//MessageBox.Show("sub2=" + strsub2);
RegexStringValidatorAttribute r1 = new RegexStringValidatorAttribute(@"^(-?[0-9]\d)$");
if (!r1.Match(strsub1))
{
MessageBox.Show("前6位应输入数字");
flag1 = false;
}
RegexStringValidatorAttribute r2 = new RegexStringValidatorAttribute(@"^(-?[a-z][A-Z]\d)$");
if (r2.Match(strsub2))
{
MessageBox.Show("第7位应输入字母");
flag2 = false;
}
if (str.Length != 9)
{
MessageBox.Show("长度不对");
flag3 = false;
}
if (flag1 == true && flag2 == true && flag3 == true)
{
MessageBox.Show("ok");
}