From 4622d34cac84d86360c0ef5694814c35889623ea Mon Sep 17 00:00:00 2001 From: milimoe Date: Wed, 8 Apr 2026 00:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=BA=90=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E6=9E=84=E9=80=A0=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Utility/General.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Api/Utility/General.cs b/Api/Utility/General.cs index bab6154..8868869 100644 --- a/Api/Utility/General.cs +++ b/Api/Utility/General.cs @@ -19,35 +19,35 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// 网络服务工具箱 /// - public class NetworkUtility + public partial class NetworkUtility { /// /// 判断字符串是否是IP地址 /// /// /// - public static bool IsIP(string str) => Regex.IsMatch(str, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); + public static bool IsIP(string str) => CheckIsIP().IsMatch(str); /// /// 判断字符串是否为邮箱地址 /// /// /// - public static bool IsEmail(string str) => Regex.IsMatch(str, @"^(\w)+(\.\w)*@(\w)+((\.\w+)+)$"); + public static bool IsEmail(string str) => CheckIsEmail().IsMatch(str); /// /// 判断字符串是否是正常的用户名(只有中英文和数字) /// /// /// - public static bool IsUserName(string str) => Regex.IsMatch(str, @"^[\u4e00-\u9fffA-Za-z0-9]+$"); + public static bool IsUserName(string str) => CheckIsUserName().IsMatch(str); /// /// 判断字符串是否是全中文的字符 /// /// /// - public static bool IsChineseName(string str) => Regex.IsMatch(str, @"^[\u4e00-\u9fff]+$"); + public static bool IsChineseName(string str) => CheckIsChineseName().IsMatch(str); /// /// 获取用户名长度 @@ -315,6 +315,15 @@ namespace Milimoe.FunGame.Core.Api.Utility } return default; } + + [GeneratedRegex(@"^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$")] + private static partial Regex CheckIsIP(); + [GeneratedRegex(@"^(\w)+(\.\w)*@(\w)+((\.\w+)+)$")] + private static partial Regex CheckIsEmail(); + [GeneratedRegex(@"^[\u4e00-\u9fffA-Za-z0-9]+$")] + private static partial Regex CheckIsUserName(); + [GeneratedRegex(@"^[\u4e00-\u9fff]+$")] + private static partial Regex CheckIsChineseName(); } #endregion