Skip to content

Commit

Permalink
feat: CIDR validation
Browse files Browse the repository at this point in the history
  • Loading branch information
infastin committed Jun 11, 2024
1 parent 41dea42 commit add6758
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions is/str/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
ErrIP = validation.NewRuleError("is_ip", "must be a valid IP address")
ErrIPv4 = validation.NewRuleError("is_ipv4", "must be a valid IPv4 address")
ErrIPv6 = validation.NewRuleError("is_ipv6", "must be a valid IPv6 address")
ErrCIDR = validation.NewRuleError("is_cidr", "must be a valid CIDR")
ErrSubdomain = validation.NewRuleError("is_sub_domain", "must be a valid subdomain")
ErrDomain = validation.NewRuleError("is_domain", "must be a valid domain")
ErrDNSName = validation.NewRuleError("is_dns_name", "must be a valid DNS name")
Expand Down Expand Up @@ -203,6 +204,13 @@ func IP[T ~string](v T) error {
return nil
}

func CIDR[T ~string](v T) error {
if !govalidator.IsCIDR(string(v)) {
return ErrCIDR
}
return nil
}

func IPv4[T ~string](v T) error {
if !govalidator.IsIPv4(string(v)) {
return ErrIPv4
Expand Down

0 comments on commit add6758

Please sign in to comment.