validatorjez

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBase64

func IsBase64(s string) bool

IsBase64 是否为base64

Example
fmt.Println(IsBase64("SGVsbG8sIHdvcmxkIQ=="))
fmt.Println(IsBase64(""))
fmt.Println(IsBase64("123"))
Output:

true
false
false

func IsBase64URL

func IsBase64URL(s string) bool

IsBase64URL 是否为base64url

Example
fmt.Println(IsBase64URL("SGVsbG8sIHdvcmxkIQ=="))
fmt.Println(IsBase64URL(""))
fmt.Println(IsBase64URL("123"))
Output:

true
false
false

func IsChineseMainlandIDCard

func IsChineseMainlandIDCard(s string) bool

IsChineseMainlandIDCard 是否为中国大陆身份证号码

Example
fmt.Println(IsChineseMainlandIDCard("210911192105130714"))
fmt.Println(IsChineseMainlandIDCard("11010519491231002X"))
fmt.Println(IsChineseMainlandIDCard("11010519491231002x"))
fmt.Println(IsChineseMainlandIDCard("123456"))
fmt.Println(IsChineseMainlandIDCard("990911192105130714"))
fmt.Println(IsChineseMainlandIDCard("210911189905130714"))
fmt.Println(IsChineseMainlandIDCard("210911222205130714"))
Output:

true
true
true
false
false
false
false

func IsChineseMainlandPhoneNumber

func IsChineseMainlandPhoneNumber(s string, withCode ...bool) bool

IsChineseMainlandPhoneNumber 是否为中国大陆手机号码, withCode为是否可包含国家代码 86 / +86

Example
fmt.Println(IsChineseMainlandPhoneNumber("13666666666"))
fmt.Println(IsChineseMainlandPhoneNumber("+8613666666666", true))
fmt.Println(IsChineseMainlandPhoneNumber("+8613666666666"))
fmt.Println(IsChineseMainlandPhoneNumber("13666"))
fmt.Println(IsChineseMainlandPhoneNumber("12666666666"))
Output:

true
true
false
false
false

func IsFloat

func IsFloat(s string) bool

IsFloat 是否为浮点数

Example
fmt.Println(IsFloat("3.14"))
fmt.Println(IsFloat("3"))
fmt.Println(IsFloat(".3"))
fmt.Println(IsFloat("3."))
fmt.Println(IsFloat("3.1.1"))
Output:

true
true
true
true
false

func IsFloatType

func IsFloatType(v any) bool

IsFloatType 是否为浮点数类型

Example
fmt.Println(IsFloatType(3.14))
fmt.Println(IsFloatType(float64(3)))
fmt.Println(IsFloatType(3.))
fmt.Println(IsFloatType(.3))
fmt.Println(IsFloatType("3.14"))
Output:

true
true
true
true
false

func IsIP

func IsIP(s string) bool

IsIP 是否为IP地址

Example
fmt.Println(IsIP("1.1.1.1"))
fmt.Println(IsIP("127.0.0.1"))
fmt.Println(IsIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
fmt.Println(IsIP("127.0.0.1:8080"))
fmt.Println(IsIP("localhost"))
Output:

true
true
true
false
false

func IsIPv4

func IsIPv4(s string) bool

IsIPv4 是否为IPv4地址

Example
fmt.Println(IsIPv4("1.1.1.1"))
fmt.Println(IsIPv4("127.0.0.1"))
fmt.Println(IsIPv4("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
fmt.Println(IsIPv4("127.0.0.1:8080"))
fmt.Println(IsIPv4("localhost"))
Output:

true
true
false
false
false

func IsIPv6

func IsIPv6(s string) bool

IsIPv6 是否为IPv6地址

Example
fmt.Println(IsIPv6("127.0.0.1"))
fmt.Println(IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
fmt.Println(IsIPv6("127.0.0.1:8080"))
fmt.Println(IsIPv6("localhost"))
Output:

false
true
false
false

func IsIn

func IsIn[T comparable](s T, list ...T) bool

IsIn 是否在指定列表中

Example
fmt.Println(IsIn(1, 1, 2, 3))
fmt.Println(IsIn(4, 1, 2, 3))
Output:

true
false

func IsInt

func IsInt(s string) bool

IsInt 是否为整数

Example
fmt.Println(IsInt("1"))
fmt.Println(IsInt("01"))
fmt.Println(IsInt("1.1"))
Output:

true
true
false

func IsIntType

func IsIntType(v any) bool

IsIntType 是否为整数类型

Example
fmt.Println(IsIntType(1))
fmt.Println(IsIntType(1.1))
fmt.Println(IsIntType("1"))
Output:

true
false
false

func IsJSON

func IsJSON(s string) bool

IsJSON 是否为json

Example
fmt.Println(IsJSON(`{"name":"tom"}`))
fmt.Println(IsJSON(`abc`))
Output:

true
false

func IsLatitude

func IsLatitude(str string) bool

IsLatitude 是否为纬度

Example
fmt.Println(IsLatitude("-74.0060"))
fmt.Println(IsLatitude("123.123"))
Output:

true
false

func IsLongitude

func IsLongitude(str string) bool

IsLongitude 是否为经度

Example
fmt.Println(IsLongitude("-45.12345"))
fmt.Println(IsLongitude("123.123.123"))
Output:

true
false

func IsNum

func IsNum(s string) bool

IsNum 是否为数字(包含浮点数)

Example
fmt.Println(IsNum("123"))
fmt.Println(IsNum("123.123"))
fmt.Println(IsNum("123.123.123"))
Output:

true
true
false

func IsNumType

func IsNumType(v any) bool

IsNumType 是否为数字类型(包含浮点数)

Example
fmt.Println(IsNumType(1))
fmt.Println(IsNumType(1.1))
fmt.Println(IsNumType("1"))
Output:

true
true
false

func IsPort

func IsPort(s string) bool

IsPort 是否为端口号

Example
fmt.Println(IsPort("65535"))
fmt.Println(IsPort("65536"))
fmt.Println(IsPort("0"))
Output:

true
false
false

func IsPrefixOrSuffix

func IsPrefixOrSuffix(s, pos string) bool

IsPrefixOrSuffix 是否以指定字符串开头或结尾

Example
fmt.Println(IsPrefixOrSuffix("123", "12"))
fmt.Println(IsPrefixOrSuffix("123", "23"))
fmt.Println(IsPrefixOrSuffix("123", "2"))
Output:

true
true
false

func IsRange

func IsRange[T constraints.Integer | constraints.Float](s, min, max T) bool

IsRange 数值范围

Example
fmt.Println(IsRange(1, 1, 2))
fmt.Println(IsRange(2, 1, 2))
fmt.Println(IsRange(3, 1, 2))
Output:

true
true
false

func IsRegex

func IsRegex(s string) bool

IsRegex 是否为正则表达式

Example
fmt.Println(IsRegex(`^[0-9]+$`))
fmt.Println(IsRegex(`abc(`))
Output:

true
false

func IsRegexMatch

func IsRegexMatch(s, regex string) bool

IsRegexMatch 是否匹配正则表达式

Example
fmt.Println(IsRegexMatch("1", `^[0-9]+$`))
fmt.Println(IsRegexMatch("2", `abc(`))
fmt.Println(IsRegexMatch("a", `^[0-9]+$`))
Output:

true
false
false

func RuneLength

func RuneLength(s string, min, max int) bool

RuneLength 字符长度

Example
fmt.Println(RuneLength("1", 1, 2))
fmt.Println(RuneLength("123", 1, 2))
Output:

true
false

func StringLength

func StringLength(s string, min, max int) bool

StringLength 字符串长度

Example
fmt.Println(StringLength("1", 1, 2))
fmt.Println(StringLength("2", 1, 2))
fmt.Println(StringLength("3", 3, 4))
Output:

true
true
false

Types

This section is empty.

Jump to

Keyboard shortcuts

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