-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidate.cs
143 lines (139 loc) · 4.65 KB
/
Validate.cs
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
135
136
137
138
139
140
141
142
143
using System;
using System.Text.RegularExpressions;
namespace MI.CloudPlatform.Util
{
public class Validate
{
/// <summary>
/// 验证手机号
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static Boolean CheckCellPhone(String text)
{
if (String.IsNullOrEmpty(text))
{
return false;
}
else
{
Regex regex = new Regex(@"^((\(\d{2,3}\))|(\d{3}\-))?((^1[34578]\d{9}))$");
if (regex.IsMatch(text))
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 验证身份证
/// </summary>
/// <param name="str"></param>
/// <returns>0:表示匹配</returns>
public static Boolean CheckIsID(string str)
{
string str1 = "0", str2 = "0";
str1 = str.Remove(str.Length - 1, 1);
Regex reg1
= new Regex(@"^[-]?\d+[.]?\d*$");
if (reg1.IsMatch(str1) == true)
{
if (str.Length == 15)
{
str2 = str1.Remove(0, 6);
str2 = str2.Remove(6, 2);
str2 = "19" + str2;
str2 = str2.Insert(4, "-");
str2 = str2.Insert(7, "-");
Regex reg2 = new Regex(@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
if (reg2.IsMatch(str2) == true)
{
return true;
}
else
{
return false;
}
}
else
{
if (str.Length == 18)
{
str2 = str1.Remove(0, 6);
str2 = str2.Remove(8, 3);
str2 = str2.Insert(4, "-");
str2 = str2.Insert(7, "-");
Regex reg2 = new Regex(@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
if (reg2.IsMatch(str2) == true)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
else
{
return false;
}
}
/// <summary>
/// 验证非中文
/// </summary>
/// <param name="text"></param>
/// <returns>0:表示匹配</returns>
public static Boolean CheckWord(string text)
{
if (String.IsNullOrEmpty(text))
{
return false;
}
else
{
Regex regex = new Regex("^[a-zA-Z0-9]+$");
if (regex.IsMatch(text))
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 验证EMAIL
/// </summary>
/// <param name="text"></param>
/// <returns>0:表示匹配</returns>
public static Boolean CheckMail(String text)
{
if (String.IsNullOrEmpty(text))
{
return false;
}
else
{
Regex regex = new Regex(@"^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.(?:com|cn)$");
if (regex.IsMatch(text))
{
return true;
}
else
{
return false;
}
}
}
}
}