OtherHelper.cs
5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace UserCtrlsByDXC
{
public class OtherHelper
{
public static bool ValidateUserInput(String _value, int _kind)
{
string RegularExpressions = null;
switch (_kind)
{
case 1:
//由26個英文字母組成的字串
RegularExpressions = "^[A-Za-z]+$";
break;
case 2:
//正整數
RegularExpressions = "^[0-9]*[1-9][0-9]*$";
break;
case 3:
//非負整數(正整數 + 0)
RegularExpressions = "^\\d+$";
break;
case 4:
//非正整數(負整數 + 0)
RegularExpressions = "^((-\\d+)|(0+))$";
break;
case 5:
//負整數
RegularExpressions = "^-[0-9]*[1-9][0-9]*$";
break;
case 6:
//整數
RegularExpressions = "^-?\\d+$";
break;
case 7:
//非負浮點數(正浮點數 + 0)
RegularExpressions = "^\\d+(\\.\\d+)?$";
break;
case 8:
//正浮點數
RegularExpressions = "^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$";
break;
case 9:
//非正浮點數(負浮點數 + 0)
RegularExpressions = "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$";
break;
case 10:
//負浮點數
RegularExpressions = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";
break;
case 11:
//浮點數
RegularExpressions = "^(-?\\d+)(\\.\\d+)?$";
break;
case 12:
//由26個英文字母的大寫組成的字串
RegularExpressions = "^[A-Z]+$";
break;
case 13:
//由26個英文字母的小寫組成的字串
RegularExpressions = "^[a-z]+$";
break;
case 14:
//由數位和26個英文字母組成的字串
RegularExpressions = "^[A-Za-z0-9]+$";
break;
case 15:
//由數位、26個英文字母或者下劃線組成的字串
RegularExpressions = "^[0-9a-zA-Z_]+$";
break;
case 16:
//email地址
RegularExpressions = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
break;
case 17:
//url
RegularExpressions = "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$";
break;
case 18:
//只能輸入中文
RegularExpressions = "^[^\u4E00-\u9FA5]";
break;
case 19:
//只能输入0和非0打头的数字
RegularExpressions = "^(0|[1-9][0-9]*)$";
break;
case 20:
//只能输入数字
RegularExpressions = "^[0-9]*$";
break;
case 21:
//只能輸入數字加2位小數
RegularExpressions = "^[0-9]+(.[0-9]{1,2})?$";
break;
case 22:
//只能输入0和非0打头的数字加2位小數
RegularExpressions = "^(0|[1-9]+)(.[0-9]{1,2})?$";
break;
case 23:
//只能输入0和非0打头的数字加2位小數 但不匹配0.00
RegularExpressions = "^(0(.(0[1-9]|[1-9][0-9]))?|[1-9]+(.[0-9]{1,2})?)$";
break;
case 24:
//只能输入ip地址
RegularExpressions = "^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$";
break;
case 25:
//5位正整數
RegularExpressions = "^[A-Z]{1}([1-9][0-9]{4})$";
break;
case 26:
//货位,格式为X-000-00-00
RegularExpressions = "^[A-Z]{1}\\-([0-9]{2})\\-([0-9]{3})\\-([0-9]{2})$";
break;
default:
break;
}
Match m = Regex.Match(_value, RegularExpressions);
if (m.Success)
return true;
else
return false;
}
}
}