例如:产品名称最多两项 并以空格隔开
1 /// <summary>
2 /// 限制产品名称个数
3 /// </summary>
4 protected bool LimitProductName()
5 {
6 char[] textstr = (txtProductName.Text).ToString().ToCharArray();
7 int temp = 0;
8 bool result = true;
9 for (int j = 0; j < textstr.Length; j++)
10 {
11 if (textstr[j] == ' ')
12 {
13 temp++;
14 }
15
16 }
17 string[] name = txtProductName.Text.Split(new char[] { ' ' });
18
19 if (temp > 0)
20 {
21
22 if (name.Length > 2)
23 {
24 Common.JavascriptHelper.Alert("产品名称最多两个并以空格隔开", this);
25 result = false;
26 }
27 }
28 //else
29 //{
30 // Common.JavascriptHelper.Alert("分隔符只能为空格", this);
31 // result = false;
32 //}
33
34 return result;
35 }
2 /// 限制产品名称个数
3 /// </summary>
4 protected bool LimitProductName()
5 {
6 char[] textstr = (txtProductName.Text).ToString().ToCharArray();
7 int temp = 0;
8 bool result = true;
9 for (int j = 0; j < textstr.Length; j++)
10 {
11 if (textstr[j] == ' ')
12 {
13 temp++;
14 }
15
16 }
17 string[] name = txtProductName.Text.Split(new char[] { ' ' });
18
19 if (temp > 0)
20 {
21
22 if (name.Length > 2)
23 {
24 Common.JavascriptHelper.Alert("产品名称最多两个并以空格隔开", this);
25 result = false;
26 }
27 }
28 //else
29 //{
30 // Common.JavascriptHelper.Alert("分隔符只能为空格", this);
31 // result = false;
32 //}
33
34 return result;
35 }