C# 增加where 判断条件 限制输入字符串长度, 正则,

//string colorNameinput = this.txtcolorName.Text.Trim();
//int colorNamecount = colorNameinput.Length;
//if (colorNamecount > 15)
//{
// MessageBox.Show(this, "商品颜色不能超过15个字");
// return;
//}
//string input = this.txtBaseNumber.Text.Trim();
//string pattern = @"^([1-9]\d{0,8})$";

//if (Regex.Match(input, pattern).Success == false)
//{
// MessageBox.Show(this, "商品库存数只能是小于9位的正整数");
// return;
//}

//string remarkinput = this.txtremark.Text.Trim();
//int remarkcount = remarkinput.Length;
//if (remarkcount > 1000)
//{
// MessageBox.Show(this, "备注信息不能超过1000个字");
// return;
//}

原文地址:https://www.cnblogs.com/codejimmygao/p/14444932.html