yzh
2022-05-26 3b18a48485f7207438d9d0eb3038d979e069431d
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
144
145
146
147
148
149
150
151
 
 
using System.Text.RegularExpressions;
 
namespace Common
{
  public class DataValidate
  {
    private static Regex RegNumber = new Regex("^[0-9]+$");
    private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");
    private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");
    private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$");
    private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$");
    private static Regex RegCHZN = new Regex("[一-龥]");
 
    protected DataValidate()
    {
    }
 
    public static bool IsAreaCode(string input)
    {
      return DataValidate.IsNumber(input) && input.Length >= 3 && input.Length <= 5;
    }
 
    public static bool IsDecimal(string input)
    {
      if (string.IsNullOrEmpty(input))
        return false;
      return Regex.IsMatch(input, "^[0-9]+[.]?[0-9]+$");
    }
 
    public static bool IsDecimalSign(string input)
    {
      if (string.IsNullOrEmpty(input))
        return false;
      return Regex.IsMatch(input, "^[+-]?[0-9]+[.]?[0-9]+$");
    }
 
    public static bool IsEmail(string strEmail)
    {
      if (string.IsNullOrEmpty(strEmail))
        return false;
      return Regex.IsMatch(strEmail, "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
    }
 
    public static bool IsIP(string strIp)
    {
      return !string.IsNullOrEmpty(strIp) && Regex.IsMatch(strIp.Trim(), "^(\\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])$");
    }
 
    public static bool IsNumber(string strNumber)
    {
      return Regex.IsMatch(strNumber, "^[0-9]+$");
    }
 
    public static bool IsNumberSign(string input)
    {
      if (string.IsNullOrEmpty(input))
        return false;
      return Regex.IsMatch(input, "^[+-]?[0-9]+$");
    }
 
    public static bool IsPostCode(string postCode)
    {
      return Regex.IsMatch(postCode, "^\\d{6}$");
    }
 
    public static bool IsMobile(string mobile)
    {
      return Regex.IsMatch(mobile, "^1[3|4|5|8]\\d{9}$") || Regex.IsMatch(mobile, "^0(([1,2]\\d)|([3-9]\\d{2}))\\d{8}$");
    }
 
    public static bool IsExistMobile(string mobile, string mobiles)
    {
      return new Regex(mobile).Match(mobiles).Success;
    }
 
    public static bool IsIdentityNumber(string num)
    {
      return Regex.IsMatch(num, "^\\d{17}[\\d|X]|\\d{15}$");
    }
 
    public static bool IsTime(string timeval)
    {
      return Regex.IsMatch(timeval, "20\\d{2}\\-[0-1]{1,2}\\-[0-3]?[0-9]?(\\s*((([0-1]?[0-9])|(2[0-3])):([0-5]?[0-9])(:[0-5]?[0-9])?))?");
    }
 
    public static bool IsURL(string url)
    {
      if (string.IsNullOrEmpty(url))
        return false;
      return Regex.IsMatch(url, "^http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$");
    }
 
    public static bool IsPhoneNumber(string phoneNumber)
    {
      return Regex.IsMatch(phoneNumber, "^(\\(\\d{3}\\)|\\d{3}-)?\\d{7,8}$");
    }
 
    public static bool IsValidId(string input)
    {
      if (string.IsNullOrEmpty(input))
        return false;
      input = input.Replace("|", "").Replace(",", "").Replace("-", "").Replace(" ", "").Trim();
      if (string.IsNullOrEmpty(input))
        return false;
      return DataValidate.IsNumber(input);
    }
 
    public static bool IsValidUserName(string userName, out string msg)
    {
      userName = userName.Trim();
      msg = "";
      if (string.IsNullOrEmpty(userName))
      {
        msg = "用户名不能为空";
        return false;
      }
      if (StringHelper.GetStringLength(userName) > 20)
      {
        msg = "用户名长度不能大于20";
        return false;
      }
      if (StringHelper.GetStringLength(userName) < 4)
      {
        msg = "用户名长度不能小于4";
        return false;
      }
      string str = "\\/\"[]:|<>+=;,?*@.";
      for (int index = 0; index < userName.Length; ++index)
      {
        if (str.IndexOf(userName[index]) >= 0)
        {
          msg = "用户名含有非法字符";
          return false;
        }
      }
      return true;
    }
 
    public static bool IsTooShortPassword(string password)
    {
      return StringHelper.GetStringLength(password.Trim()) < 6;
    }
 
    public static bool IsHasCHZN(string inputData)
    {
      return DataValidate.RegCHZN.Match(inputData).Success;
    }
  }
}