Browse Source

验证外呼号码是否需要加0

tangjiang 6 months ago
parent
commit
ee63205772
1 changed files with 33 additions and 0 deletions
  1. 33 0
      src/Hotline.Application/Systems/SystemMobilAreaApplication.cs

+ 33 - 0
src/Hotline.Application/Systems/SystemMobilAreaApplication.cs

@@ -73,6 +73,39 @@ namespace Hotline.Application.Systems
             return areaDto;
         }
 
+        /// <summary>
+        /// 验证电话外呼是否需要加0
+        /// </summary>
+        /// <param name="Mobile"></param>
+        /// <returns></returns>
+        public async Task<string> VaildMobile(string Mobile)
+        {
+            // 验证是否存在0
+            if (false == string.IsNullOrWhiteSpace(Mobile))
+            {
+                // 前缀是否为0
+                string firstChar = Mobile.Substring(0, 1);
+                if (firstChar == "0" && Mobile.Length > 1)
+                {
+                    Mobile = Mobile.Substring(1, Mobile.Length - 1);
+                }
+                Regex regex = new Regex("^1[0-9]{10}$");
+                bool bCheck = regex.IsMatch(Mobile);
+                if (true == bCheck)
+                {// 是手机号码
+                 // 获取前7位
+                    string sevenChar = Mobile.Substring(0, 7);
+
+                    var data = await _systemMobilAreaRepository.GetAsync(p => p.MobileAreaName == "四川省自贡市" && p.MobileCode == sevenChar);
+                    if (data is null)
+                    {
+                        Mobile = "0" + Mobile;
+                    }
+                }
+            }
+            // 返回结果
+            return Mobile;
+        }
 
         #region 验证手机号码
         /// <summary>