Documentation ¶
Index ¶
- func IsBase64(s string) bool
- func IsBase64URL(s string) bool
- func IsChineseMainlandIDCard(s string) bool
- func IsChineseMainlandPhoneNumber(s string, withCode ...bool) bool
- func IsFloat(s string) bool
- func IsFloatType(v any) bool
- func IsIP(s string) bool
- func IsIPv4(s string) bool
- func IsIPv6(s string) bool
- func IsIn[T comparable](s T, list ...T) bool
- func IsInt(s string) bool
- func IsIntType(v any) bool
- func IsJSON(s string) bool
- func IsLatitude(str string) bool
- func IsLongitude(str string) bool
- func IsNum(s string) bool
- func IsNumType(v any) bool
- func IsPort(s string) bool
- func IsPrefixOrSuffix(s, pos string) bool
- func IsRange[T constraints.Integer | constraints.Float](s, min, max T) bool
- func IsRegex(s string) bool
- func IsRegexMatch(s, regex string) bool
- func RuneLength(s string, min, max int) bool
- func StringLength(s string, min, max int) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBase64 ¶
IsBase64 是否为base64
Example ¶
fmt.Println(IsBase64("SGVsbG8sIHdvcmxkIQ==")) fmt.Println(IsBase64("")) fmt.Println(IsBase64("123"))
Output: true false false
func IsBase64URL ¶
IsBase64URL 是否为base64url
Example ¶
fmt.Println(IsBase64URL("SGVsbG8sIHdvcmxkIQ==")) fmt.Println(IsBase64URL("")) fmt.Println(IsBase64URL("123"))
Output: true false false
func IsChineseMainlandIDCard ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
IsInt 是否为整数
Example ¶
fmt.Println(IsInt("1")) fmt.Println(IsInt("01")) fmt.Println(IsInt("1.1"))
Output: true true false
func IsIntType ¶
IsIntType 是否为整数类型
Example ¶
fmt.Println(IsIntType(1)) fmt.Println(IsIntType(1.1)) fmt.Println(IsIntType("1"))
Output: true false false
func IsJSON ¶
IsJSON 是否为json
Example ¶
fmt.Println(IsJSON(`{"name":"tom"}`)) fmt.Println(IsJSON(`abc`))
Output: true false
func IsLatitude ¶
IsLatitude 是否为纬度
Example ¶
fmt.Println(IsLatitude("-74.0060")) fmt.Println(IsLatitude("123.123"))
Output: true false
func IsLongitude ¶
IsLongitude 是否为经度
Example ¶
fmt.Println(IsLongitude("-45.12345")) fmt.Println(IsLongitude("123.123.123"))
Output: true false
func IsNum ¶
IsNum 是否为数字(包含浮点数)
Example ¶
fmt.Println(IsNum("123")) fmt.Println(IsNum("123.123")) fmt.Println(IsNum("123.123.123"))
Output: true true false
func IsNumType ¶
IsNumType 是否为数字类型(包含浮点数)
Example ¶
fmt.Println(IsNumType(1)) fmt.Println(IsNumType(1.1)) fmt.Println(IsNumType("1"))
Output: true true false
func IsPort ¶
IsPort 是否为端口号
Example ¶
fmt.Println(IsPort("65535")) fmt.Println(IsPort("65536")) fmt.Println(IsPort("0"))
Output: true false false
func IsPrefixOrSuffix ¶
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 ¶
IsRegex 是否为正则表达式
Example ¶
fmt.Println(IsRegex(`^[0-9]+$`)) fmt.Println(IsRegex(`abc(`))
Output: true false
func IsRegexMatch ¶
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 ¶
RuneLength 字符长度
Example ¶
fmt.Println(RuneLength("1", 1, 2)) fmt.Println(RuneLength("123", 1, 2))
Output: true false
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.