DigitalFactory/Admin.NET/Admin.NET.Core/Util/RegularValidate.cs

34 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 大名科技(天津)有限公司版权所有 电话18020030720 QQ515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core;
/// <summary>
/// 正则校验
/// </summary>
public static class RegularValidate
{
/// <summary>
/// 验证密码规则
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public static bool ValidatePassword(string password)
{
var regex = new Regex(@"
(?=.*[0-9]) #必须包含数字
(?=.*[a-z]) #必须包含小写
(?=.*[A-Z]) #必须包含大写
(?=([\x21-\x7e]+)[^a-zA-Z0-9]) #必须包含特殊符号
.{8,30} #至少8个字符最多30个字符
", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
//如果要求必须包含小写、大写字母,则上面的(?=.*[a-zA-Z]) 要改为:
/*
* (?=.*[a-z])
* (?=.*[A-Z])
*/
return regex.IsMatch(password);
}
}