validationutils

package
v0.0.0-...-98f1bff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package validationutils 提供数据验证相关的工具函数

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsLowercase

func ContainsLowercase(str string) bool

ContainsLowercase 验证字符串是否包含小写字母 参数:

  • str: 要验证的字符串

返回:

  • bool: 是否包含小写字母

func ContainsSpecialChar

func ContainsSpecialChar(str string, specialChars string) bool

ContainsSpecialChar 验证字符串是否包含特殊字符 参数:

  • str: 要验证的字符串
  • specialChars: 特殊字符集(如果为空,则使用默认特殊字符集)

返回:

  • bool: 是否包含特殊字符

func ContainsUppercase

func ContainsUppercase(str string) bool

ContainsUppercase 验证字符串是否包含大写字母 参数:

  • str: 要验证的字符串

返回:

  • bool: 是否包含大写字母

func HasMaxLength

func HasMaxLength(str string, maxLength int) bool

HasMaxLength 验证字符串是否不超过最大长度 参数:

  • str: 要验证的字符串
  • maxLength: 最大长度

返回:

  • bool: 是否不超过最大长度

func HasMinLength

func HasMinLength(str string, minLength int) bool

HasMinLength 验证字符串是否达到最小长度 参数:

  • str: 要验证的字符串
  • minLength: 最小长度

返回:

  • bool: 是否达到最小长度

func IsAlpha

func IsAlpha(str string) bool

IsAlpha 验证字符串是否只包含字母 参数:

  • str: 要验证的字符串

返回:

  • bool: 是否只包含字母

func IsAlphaNumeric

func IsAlphaNumeric(str string) bool

IsAlphaNumeric 验证字符串是否只包含字母和数字 参数:

  • str: 要验证的字符串

返回:

  • bool: 是否只包含字母和数字

func IsCNIDCard

func IsCNIDCard(idCard string) bool

IsCNIDCard 验证字符串是否为有效的中国身份证号码 参数:

  • idCard: 要验证的身份证号码

返回:

  • bool: 是否为有效的中国身份证号码

func IsCNMobile

func IsCNMobile(mobile string) bool

IsCNMobile 验证字符串是否为有效的中国大陆手机号 参数:

  • mobile: 要验证的手机号

返回:

  • bool: 是否为有效的中国大陆手机号

func IsEmail

func IsEmail(email string) bool

IsEmail 验证字符串是否为有效的电子邮件地址 参数:

  • email: 要验证的电子邮件地址

返回:

  • bool: 是否为有效的电子邮件地址

func IsIPv4

func IsIPv4(ip string) bool

IsIPv4 验证字符串是否为有效的IPv4地址 参数:

  • ip: 要验证的IP地址

返回:

  • bool: 是否为有效的IPv4地址

func IsInRange

func IsInRange(value, minValue, maxValue int) bool

IsInRange 验证数值是否在指定范围内 参数:

  • value: 要验证的数值
  • minValue: 最小值
  • maxValue: 最大值

返回:

  • bool: 是否在指定范围内

func IsNumeric

func IsNumeric(str string) bool

IsNumeric 验证字符串是否只包含数字 参数:

  • str: 要验证的字符串

返回:

  • 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: 不满足的规则列表

func IsPostalCode

func IsPostalCode(code string) bool

IsPostalCode 验证字符串是否为有效的中国邮政编码 参数:

  • code: 要验证的邮政编码

返回:

  • bool: 是否为有效的中国邮政编码

func IsURL

func IsURL(url string) bool

IsURL 验证字符串是否为有效的URL 参数:

  • url: 要验证的URL

返回:

  • bool: 是否为有效的URL

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: 密码强度检查结果

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL