validator

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AlphaMatcher         = regexp.MustCompile(`^[a-zA-Z]+$`)
	LetterRegexMatcher   = regexp.MustCompile(`[a-zA-Z]`)
	NumberRegexMatcher   = regexp.MustCompile(`\d`)
	IntStrMatcher        = regexp.MustCompile(`^[\+-]?\d+$`)
	UrlMatcher           = regexp.MustCompile(`^((ftp|http|https?):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`)
	DnsMatcher           = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`)
	EmailMatcher         = regexp.MustCompile(`\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`)
	ChineseMobileMatcher = regexp.MustCompile(`^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$`)
	ChineseIdMatcher     = regexp.MustCompile(`^[1-9]\d{5}(18|19|20|21|22)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$`)
	ChineseMatcher       = regexp.MustCompile("[\u4e00-\u9fa5]")
	ChinesePhoneMatcher  = regexp.MustCompile(`\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}`)
	CreditCardMatcher    = regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11}|6[27][0-9]{14})$`)
	Base64Matcher        = regexp.MustCompile(`^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$`)
)

Functions

func ContainLower

func ContainLower(str string) bool

ContainLower check if the string contain at least one lower case letter a-z. Play: https://go.dev/play/p/Srqi1ItvnAA

func ContainUpper

func ContainUpper(str string) bool

ContainUpper check if the string contain at least one upper case letter A-Z. Play: https://go.dev/play/p/CmWeBEk27-z

func IsASCII

func IsASCII(str string) bool

IsASCII checks if string is all ASCII char. Play: https://go.dev/play/p/hfQNPLX0jNa

func IsAllLower

func IsAllLower(str string) bool

IsAllLower check if the string is all lower case letters a-z. Play: https://go.dev/play/p/GjqCnOfV6cM

func IsAllUpper

func IsAllUpper(str string) bool

IsAllUpper check if the string is all upper case letters A-Z. Play: https://go.dev/play/p/ZHctgeK1n4Z

func IsEmptyString

func IsEmptyString(str string) bool

IsEmptyString check if the string is empty. Play: https://go.dev/play/p/dpzgUjFnBCX

func IsFloat

func IsFloat(v any) bool

IsFloat check if the value is float(float32, float34) or not. Play: https://go.dev/play/p/vsyG-sxr99_Z

func IsFloatStr

func IsFloatStr(str string) bool

IsFloatStr check if the string can convert to a float. Play: https://go.dev/play/p/LOYwS_Oyl7U

func IsInt

func IsInt(v any) bool

IsInt check if the value is integer(int, unit) or not. Play: https://go.dev/play/p/eFoIHbgzl-z

func IsIntStr

func IsIntStr(str string) bool

IsIntStr check if the string can convert to a integer. Play: https://go.dev/play/p/jQRtFv-a0Rk

func IsIp

func IsIp(ipstr string) bool

IsIp check if the string is a ip address. Play: https://go.dev/play/p/FgcplDvmxoD

func IsIpV4

func IsIpV4(ipstr string) bool

IsIpV4 check if the string is a ipv4 address. Play: https://go.dev/play/p/zBGT99EjaIu

func IsIpV6

func IsIpV6(ipstr string) bool

IsIpV6 check if the string is a ipv6 address. Play: https://go.dev/play/p/AHA0r0AzIdC

func IsJSON

func IsJSON(str string) bool

IsJSON checks if the string is valid JSON. Play: https://go.dev/play/p/8Kip1Itjiil

func IsNumber

func IsNumber(v any) bool

IsNumber check if the value is number(integer, float) or not. Play: https://go.dev/play/p/mdJHOAvtsvF

func IsNumberStr

func IsNumberStr(s string) bool

IsNumberStr check if the string can convert to a number. Play: https://go.dev/play/p/LzaKocSV79u

func IsPort

func IsPort(str string) bool

IsPort check if the string is a valid net port. Play:

func IsPrintable

func IsPrintable(str string) bool

IsPrintable checks if string is all printable chars. Play: https://go.dev/play/p/Pe1FE2gdtTP

func IsRegexMatch

func IsRegexMatch(str, regex string) bool

IsRegexMatch check if the string match the regexp. Play: https://go.dev/play/p/z_XeZo_litG

func IsStrongPassword

func IsStrongPassword(password string, length int) bool

IsStrongPassword check if the string is strong password, if len(password) is less than the length param, return false Strong password: alpha(lower+upper) + number + special chars(!@#$%^&*()?><). Play: https://go.dev/play/p/QHdVcSQ3uDg

func IsUrl

func IsUrl(str string) bool

IsUrl check if the string is url. Play: https://go.dev/play/p/pbJGa7F98Ka

func IsWeakPassword

func IsWeakPassword(password string) bool

IsWeakPassword check if the string is weak password Weak password: only letter or only number or letter + number. Play: https://go.dev/play/p/wqakscZH5gH

func RegexMatch

func RegexMatch(str string, regex *regexp.Regexp) bool

RegexMatch check if the string match the regexp.

Types

This section is empty.

Jump to

Keyboard shortcuts

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