validator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package validator 符合 web.filter 的验证器

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha(s string) bool

func And

func And[T any](v ...func(T) bool) filter.ValidatorFuncOf[T]

func Ascii

func Ascii(s string) bool

func BankCard

func BankCard(val string) bool

BankCard 是否为正确的银行卡号

func Between

func Between[T Number](min, max T) filter.ValidatorFuncOf[T]

Between 判断数值区间 (min, max)

func BetweenEqual

func BetweenEqual[T Number](min, max T) filter.ValidatorFuncOf[T]

BetweenEqual 判断数值区间 [min, max]

func CNMobile

func CNMobile(val string) bool

CNMobile 验证中国大陆的手机号码

func CNPhone

func CNPhone(val string) bool

CNPhone 验证中国大陆的电话号码

支持如下格式:

0578-12345678-1234
057812345678-1234

若存在分机号,则分机号的连接符不能省略。

func CNTel

func CNTel(val string) bool

CNTel 验证手机和电话类型

func Email

func Email(val string) bool

func EndWith

func EndWith(suffix string) filter.ValidatorFuncOf[string]

func Equal

func Equal[T comparable](v T) filter.ValidatorFuncOf[T]

Equal 生成判断值是否等于 v 的验证器

func GB11643

func GB11643(val string) bool

GB11643 判断一个身份证是否符合 gb11643 标准

若是 15 位则当作一代身份证,仅简单地判断各位是否都是数字; 若是 18 位则当作二代身份证,会计算校验位是否正确;

func GB32100

func GB32100(val string) bool

GB32100 统一信用代码校验

func Great

func Great[T Number](num T) filter.ValidatorFuncOf[T]

func GreatEqual

func GreatEqual[T Number](num T) filter.ValidatorFuncOf[T]

func HexColor

func HexColor(val string) bool

HexColor 判断一个字符串是否为合法的 16 进制颜色表示法

func IP

func IP(val string) bool

func IP4

func IP4(val string) bool

func IP6

func IP6(val string) bool

func ISBN

func ISBN(val string) bool

ISBN 判断是否为合法的 ISBN 串号

可以同时判断 ISBN10 和 ISBN13

func ISBN10

func ISBN10(val string) bool

func ISBN13

func ISBN13(val string) bool

func In

func In[T comparable](element ...T) filter.ValidatorFuncOf[T]

In 声明枚举类型的验证规则

要求验证的值必须包含在 element 元素中,如果不存在,则返回 msg 的内容。

func Less

func Less[T Number](num T) filter.ValidatorFuncOf[T]

func LessEqual

func LessEqual[T Number](num T) filter.ValidatorFuncOf[T]

func Luhn

func Luhn(val string) bool

Luhn 验证 luhn 算法

func Match

Match 为正则生成验证函数

func Not

func Not[T any](v func(T) bool) filter.ValidatorFuncOf[T]

func NotIn

func NotIn[T comparable](element ...T) filter.ValidatorFuncOf[T]

NotIn 声明不在枚举中的验证规则

func Or

func Or[T any](v ...func(T) bool) filter.ValidatorFuncOf[T]

func StartWith

func StartWith(prefix string) filter.ValidatorFuncOf[string]

func Strength

func Strength(length, upper, lower, punct int) filter.ValidatorFuncOf[string]

Strength 声明密码强度的验证对象

length 对长度的最小要求; upper 对大写字符的最小要求; lower 对小写字符的最小要求; punct 对符号的最小要求;

func URL

func URL(val string) bool

func Zero

func Zero[T any](v T) bool

Types

type Number

type Number interface {
	float32 | float64 |
		~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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