killapp/Assets/Scripts/Utils/ValidationUtils.cs
“虞渠成” c27ef0847a refactor(home schedule): 调整定时任务筛选和展示逻辑,更新多语言文案
1. 优化密码校验正则,支持全角特殊字符
2. 更新首页无定时任务的多语言文案
3. 重构今日任务查找逻辑,仅筛选未开始任务并简化展示
2026-06-29 14:01:49 +08:00

70 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Text.RegularExpressions;
namespace Kill.Utils
{
/// <summary>
/// 验证工具类
/// 提供常用的数据验证方法
/// </summary>
public static class ValidationUtils
{
#region
/// <summary>
/// 验证邮箱格式是否有效(正则验证,更严格)
/// </summary>
public static bool IsValidEmailStrict(string email)
{
if (string.IsNullOrEmpty(email))
return false;
// RFC 5322 标准邮箱正则
string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
return Regex.IsMatch(email, pattern);
}
#endregion
#region
/// <summary>
/// 验证简单密码格式6位数字
/// </summary>
public static bool IsValidSimplePassword(string password)
{
if (string.IsNullOrEmpty(password))
return false;
// 6位数字
string pattern = @"^\d{6}$";
return Regex.IsMatch(password, pattern);
}
/// <summary>
/// 验证复杂密码格式6-16位同时包含数字、字母和特殊字符
/// </summary>
public static bool IsValidComplexPassword(string password)
{
if (string.IsNullOrEmpty(password))
return false;
// 长度6-16位
if (password.Length < 6 || password.Length > 16)
return false;
// 必须包含数字
bool hasDigit = Regex.IsMatch(password, @"\d");
// 必须包含字母
bool hasLetter = Regex.IsMatch(password, @"[a-zA-Z]");
// 必须包含特殊字符(支持半角和全角符号)
bool hasSpecial = Regex.IsMatch(password, @"[!@#$%^&*()_+\-=\[\]{};':""\\|,.<>\/?]|\p{P}");
return hasDigit && hasLetter && hasSpecial;
}
#endregion
}
}