From 1cb49b04ae6709e6054c328f5ed12bff9ca014c8 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期二, 12 十一月 2024 09:21:57 +0800
Subject: [PATCH] no message
---
CoreCms.Net.Utility/Extensions/StringExtensions.cs | 61 ++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 1 deletions(-)
diff --git a/CoreCms.Net.Utility/Extensions/StringExtensions.cs b/CoreCms.Net.Utility/Extensions/StringExtensions.cs
index 10bb5cb..c23a1af 100644
--- a/CoreCms.Net.Utility/Extensions/StringExtensions.cs
+++ b/CoreCms.Net.Utility/Extensions/StringExtensions.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CoreCms.Net.Utility.Extensions
@@ -25,6 +26,64 @@
}
return defaultValue;
}
-
+
+ /// <summary>
+ /// 灏唝yyy-MM-dd'T'HH:mm:ss~yyyy-MM-dd'T'HH:mm:ss 鏍煎紡鏈猄tartDate 鍜宔nddata
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public static (DateTime? StartDate, DateTime? EndDate) ParseDateTimeRange(this string input)
+ {
+ // 瀹氫箟鏃ユ湡鏃堕棿鏍煎紡
+ string format = "yyyy-MM-dd'T'HH:mm:ss";
+
+ // 鎷嗗垎瀛楃涓�
+ string[] parts = input.Split('~');
+
+ if (parts.Length == 2)
+ {
+ // 瑙f瀽寮�濮嬫椂闂�
+ DateTime startDate;
+ bool isStartDateValid = DateTime.TryParseExact(parts[0], format, null, System.Globalization.DateTimeStyles.None, out startDate);
+
+ // 瑙f瀽缁撴潫鏃堕棿
+ DateTime endDate;
+ bool isEndDateValid = DateTime.TryParseExact(parts[1], format, null, System.Globalization.DateTimeStyles.None, out endDate);
+
+ if (isStartDateValid && isEndDateValid)
+ {
+ if(startDate<endDate)
+ return (startDate, endDate);
+ else
+ {
+ return (null, null);
+ }
+ }
+ else if (isStartDateValid)
+ {
+ return (startDate, null);
+ }
+ else if (isEndDateValid)
+ {
+ return (null, endDate);
+ }
+ }
+
+ // 濡傛灉杈撳叆瀛楃涓叉牸寮忎笉姝g‘鎴栬В鏋愬け璐ワ紝杩斿洖 (null, null)
+ return (null, null);
+ }
+ /// <summary>
+ /// 鏍¢獙鏄惁鏄墜鏈哄彿鐮�
+ /// </summary>
+ /// <param name="phoneNumber"></param>
+ /// <returns></returns>
+ public static bool IsPhoneNumberValid(this string phoneNumber)
+ {
+ // 瀹氫箟姝e垯琛ㄨ揪寮忔ā寮�
+ string pattern = @"^1[3-9]\d{9}$";
+
+ // 浣跨敤 Regex.IsMatch 鏂规硶杩涜鍖归厤
+ return Regex.IsMatch(phoneNumber, pattern);
+ }
}
}
--
Gitblit v1.9.1