懒得勤快 5 years ago
parent
commit
c182322ab7

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.1</TargetFramework>
-    <Version>2.2.8.7</Version>
+    <Version>2.2.8.8</Version>
     <Authors>懒得勤快</Authors>
     <Company>masuit.com</Company>
     <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。

+ 13 - 2
Masuit.Tools/Extensions.cs

@@ -657,6 +657,12 @@ namespace Masuit.Tools
         /// <returns>匹配对象</returns>
         public static Match MatchEmail(this string s, out bool isMatch)
         {
+            if (string.IsNullOrEmpty(s))
+            {
+                isMatch = false;
+                return null;
+            }
+
             Match match = Regex.Match(s, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
             isMatch = match.Success;
             return isMatch ? match : null;
@@ -809,6 +815,11 @@ namespace Masuit.Tools
         /// <returns>匹配对象</returns>
         public static Match MatchPhoneNumber(this string s, out bool isMatch)
         {
+            if (string.IsNullOrEmpty(s))
+            {
+                isMatch = false;
+                return null;
+            }
             Match match = Regex.Match(s, @"^((1[3,5,6,8][0-9])|(14[5,7])|(17[0,1,3,6,7,8])|(19[8,9]))\d{8}$");
             isMatch = match.Success;
             return isMatch ? match : null;
@@ -1302,8 +1313,8 @@ namespace Masuit.Tools
             string masks = new string(new[] { mask, mask, mask, mask });
             return s.Length switch
             {
-                _ when s.Length > 4 => Regex.Replace(s, "(\\w{3})\\w+(\\w{4})", $"$1{masks}$2"),
-                _ when s.Length >= 2 && s.Length <= 4 => Regex.Replace(s, "(\\w{1})\\w*(\\w{1})", $"$1{masks}$2"),
+                _ when s.Length >= 7 => Regex.Replace(s, @"(\w{3})\w*(\w{4})", $"$1{masks}$2"),
+                _ when s.Length >= 2 && s.Length < 7 => Regex.Replace(s, @"(\w{1})\w*(\w{1})", $"$1{masks}$2"),
                 _ => s + masks
             };
         }

BIN
Masuit.Tools/Properties/AssemblyInfo.cs


+ 1 - 1
Masuit.Tools/package.nuspec

@@ -4,7 +4,7 @@
     <!--*-->
     <id>Masuit.Tools.Net</id>
     <!--*-->
-    <version>2.2.8.7</version>
+    <version>2.2.8.8</version>
     <title>Masuit.Tools</title>
     <!--*-->
     <authors>masuit.com</authors>