Documentation
¶
Overview ¶
Package validationutils 提供数据验证相关的工具函数
Index ¶
- func ContainsLowercase(str string) bool
- func ContainsSpecialChar(str string, specialChars string) bool
- func ContainsUppercase(str string) bool
- func HasMaxLength(str string, maxLength int) bool
- func HasMinLength(str string, minLength int) bool
- func IsAlpha(str string) bool
- func IsAlphaNumeric(str string) bool
- func IsCNIDCard(idCard string) bool
- func IsCNMobile(mobile string) bool
- func IsEmail(email string) bool
- func IsIPv4(ip string) bool
- func IsInRange(value, minValue, maxValue int) bool
- func IsNumeric(str string) bool
- func IsPasswordValid(password string, minLength int, ...) (bool, []string)
- func IsPostalCode(code string) bool
- func IsURL(url string) bool
- type PasswordStrengthLevel
- type PasswordStrengthResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsSpecialChar ¶
ContainsSpecialChar 验证字符串是否包含特殊字符 参数:
- str: 要验证的字符串
- specialChars: 特殊字符集(如果为空,则使用默认特殊字符集)
返回:
- bool: 是否包含特殊字符
func HasMaxLength ¶
HasMaxLength 验证字符串是否不超过最大长度 参数:
- str: 要验证的字符串
- maxLength: 最大长度
返回:
- bool: 是否不超过最大长度
func IsInRange ¶
IsInRange 验证数值是否在指定范围内 参数:
- value: 要验证的数值
- minValue: 最小值
- maxValue: 最大值
返回:
- bool: 是否在指定范围内
func IsPasswordValid ¶
func IsPasswordValid(password string, minLength int, requireUpper, requireLower, requireDigit, requireSpecial bool) (bool, []string)
IsPasswordValid 根据指定的规则验证密码是否有效 参数:
- password: 要验证的密码
- minLength: 最小长度
- requireUpper: 是否要求包含大写字母
- requireLower: 是否要求包含小写字母
- requireDigit: 是否要求包含数字
- requireSpecial: 是否要求包含特殊字符
返回:
- bool: 密码是否有效
- []string: 不满足的规则列表
Types ¶
type PasswordStrengthLevel ¶
type PasswordStrengthLevel int
PasswordStrengthLevel 密码强度级别
const ( // WeakPassword 弱密码 WeakPassword PasswordStrengthLevel = iota // MediumPassword 中等强度密码 MediumPassword // StrongPassword 强密码 StrongPassword // VeryStrongPassword 非常强的密码 VeryStrongPassword )
type PasswordStrengthResult ¶
type PasswordStrengthResult struct { // Level 密码强度级别 Level PasswordStrengthLevel // Score 密码强度得分(0-100) Score int // Suggestions 改进建议 Suggestions []string }
PasswordStrengthResult 密码强度检查结果
func CheckPasswordStrength ¶
func CheckPasswordStrength(password string) PasswordStrengthResult
CheckPasswordStrength 检查密码强度 参数:
- password: 要检查的密码
返回:
- PasswordStrengthResult: 密码强度检查结果
Click to show internal directories.
Click to hide internal directories.