Golidators is a golang package, it includes basic data validation functions and regexes
~$ go get github.com/eredotpkfr/golidators
Following validators available on this package:
- Domain
- MD5, SHA1, SHA224, SHA256, SHA512
- IPv4, IPv4CIDR, IPv6, IPv6CIDR
- MAC
- Port
- URL
- UUID
- CreditCard/Luhn
Just import and use it. Also see documentation at pkg.go.dev
package main
import (
"github.com/eredotpkfr/golidators"
"fmt"
)
func main() {
// Validate domain address
fmt.Println(golidators.Domain("www.example.com"))
// Validate IPv4 address
fmt.Println(golidators.Ipv4("::1"))
// Validate IPv6 address
fmt.Println(golidators.Ipv6("::1"))
// Validate URL
fmt.Println(golidators.Url("https://www.example.com"))
// Validate IPv4CIDR
fmt.Println(golidators.Ipv4Cidr("127.0.0.1/12"))
// Validate most common hashes
fmt.Println(golidators.Md5("foo/bar"))
// Validate with Luhn algorithm
fmt.Println(golidators.Luhn(5300025108592596))
// Calculate check digit with Luhn algorithm
fmt.Println(golidators.LuhnCheckDigit(5146713835433))
// Validate credit card number with Luhn
fmt.Println(golidators.CreditCard(5184214431476070))
}
Blog - erdoganyoksul.com
Mail - [email protected]