validation

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

validation

校验工具:邮箱、手机号、URL、IP、UUID、信用卡号、JSON 等验证。

安装

import "github.com/Ccmuyu/gopkg/validation"

快速开始

validation.IsEmail("test@example.com")           // true
validation.IsPhone("13812345678")                // true
validation.IsURL("https://example.com")          // true
validation.IsIP("192.168.1.1")                   // true
validation.IsUUID("550e8400-e29b-41d4-a716-446655440000") // true
validation.IsCreditCard("4111111111111111")       // true
validation.IsJSON(`{"key":"value"}`)             // true
validation.IsMAC("00:1A:2B:3C:4D:5E")            // true

API 参考

func IsEmail(s string) bool
func IsPhone(s string) bool
func IsURL(s string) bool
func IsIP(s string) bool
func IsIPv4(s string) bool
func IsAlpha(s string) bool
func IsNumeric(s string) bool
func IsAlphanumeric(s string) bool
func IsMatch(s string, pattern string) bool
func IsEmailAddr(s string) bool
func IsPrivateIP(s string) bool
func IsUUID(s string) bool
func IsMAC(s string) bool
func IsJSON(s string) bool
func IsHexColor(s string) bool
func IsPostalCode(s string) bool
func IsPort(port int) bool
func IsLatitude(lat float64) bool
func IsLongitude(lng float64) bool
func IsCreditCard(s string) bool

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlpha

func IsAlpha(s string) bool

func IsAlphanumeric

func IsAlphanumeric(s string) bool

func IsCreditCard added in v1.2.0

func IsCreditCard(s string) bool
Example
fmt.Println(IsCreditCard("4111111111111111"))
fmt.Println(IsCreditCard("1234567890123456"))
Output:
true
false

func IsEmail

func IsEmail(s string) bool

func IsEmailAddr

func IsEmailAddr(s string) bool

func IsHexColor added in v1.2.0

func IsHexColor(s string) bool

func IsIP

func IsIP(s string) bool

func IsIPv4

func IsIPv4(s string) bool

func IsJSON added in v1.2.0

func IsJSON(s string) bool
Example
fmt.Println(IsJSON(`{"key":"value"}`))
fmt.Println(IsJSON(`{invalid}`))
Output:
true
false

func IsLatitude added in v1.2.0

func IsLatitude(lat float64) bool

func IsLongitude added in v1.2.0

func IsLongitude(lng float64) bool

func IsMAC added in v1.2.0

func IsMAC(s string) bool

func IsMatch

func IsMatch(s string, pattern string) bool

func IsNumeric

func IsNumeric(s string) bool

func IsPhone

func IsPhone(s string) bool

func IsPort added in v1.2.0

func IsPort(port int) bool

func IsPostalCode added in v1.2.0

func IsPostalCode(s string) bool

func IsPrivateIP

func IsPrivateIP(s string) bool

func IsURL

func IsURL(s string) bool

func IsUUID added in v1.2.0

func IsUUID(s string) bool
Example
fmt.Println(IsUUID("550e8400-e29b-41d4-a716-446655440000"))
fmt.Println(IsUUID("not-a-uuid"))
Output:
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