is

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package is provides pure syntax predicates for common string formats: network addresses, identifiers, encodings and coordinates. Each function reports whether s has the format; none performs I/O or network lookups, so Email does not check deliverability and Hostname does not resolve. The validator package's format rules delegate to them, and they are usable on their own. All functions are safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64

func Base64(s string) bool

Base64 reports standard (RFC 4648 section 4) base64 with padding and no line breaks; empty input and the URL-safe alphabet fail.

func CIDR added in v0.2.0

func CIDR(s string) bool

CIDR reports IPv4 or IPv6 CIDR notation as accepted by net.ParseCIDR ("10.0.0.0/8", "2001:db8::/32"); host bits may be set.

func CIDRv4 added in v0.2.0

func CIDRv4(s string) bool

CIDRv4 reports IPv4 CIDR notation only.

func CIDRv6 added in v0.2.0

func CIDRv6(s string) bool

CIDRv6 reports IPv6 CIDR notation only.

func CreditCard added in v0.2.0

func CreditCard(s string) bool

CreditCard reports a 12 to 19 digit card number passing Luhn; spaces and dashes between digit groups are ignored. Issuer prefixes are not checked.

func E164 added in v0.2.0

func E164(s string) bool

E164 reports an international phone number in E.164 form: a "+" followed by 2 to 15 digits with no leading zero (+14155552671). No separators are allowed.

func Email

func Email(s string) bool

Email reports an RFC 5322 style address with a dotted domain: the local part is at most 64 bytes, the domain at most 255, the whole address at most 254. Quoted local parts and non-ASCII letters are accepted. It is a syntax check only; no DNS or deliverability lookup is done.

func FQDN added in v0.2.0

func FQDN(s string) bool

FQDN reports a fully qualified domain name: Hostname's label rules plus at least one dot and a top-level domain that starts with a letter, so "localhost" and numeric TLDs fail.

func HexColor added in v0.2.0

func HexColor(s string) bool

HexColor reports a "#"-prefixed CSS hex color with 3, 4, 6 or 8 hex digits, in either case.

func Hostname

func Hostname(s string) bool

Hostname reports an RFC 1123 host name of at most 253 bytes: dot-separated labels of letters, digits and hyphens, each 1 to 63 bytes and neither starting nor ending with a hyphen. A single label ("localhost") and a trailing root dot are accepted; FQDN additionally requires a top-level domain.

func IP

func IP(s string) bool

IP reports an IPv4 or IPv6 address literal as accepted by net.ParseIP; zone suffixes ("fe80::1%eth0") and CIDR prefixes fail.

func IPv4

func IPv4(s string) bool

IPv4 reports a dotted-quad IPv4 address; IPv4-mapped IPv6 forms such as "::ffff:1.2.3.4" fail.

func IPv6

func IPv6(s string) bool

IPv6 reports an IPv6 address literal, including IPv4-mapped forms such as "::ffff:1.2.3.4".

func JSON

func JSON(s string) bool

JSON reports well-formed JSON of any kind (object, array or scalar); empty input fails.

func JWT added in v0.2.0

func JWT(s string) bool

JWT reports the shape of a compact JWS: three dot-separated base64url segments, the last possibly empty (unsecured token). The signature is not verified and the payload is not decoded.

func Latitude added in v0.2.0

func Latitude(s string) bool

Latitude reports a decimal latitude in [-90, 90] with an optional sign and fraction; exponents and whitespace fail.

func Longitude added in v0.2.0

func Longitude(s string) bool

Longitude reports a decimal longitude in [-180, 180] with an optional sign and fraction; exponents and whitespace fail.

func Luhn added in v0.2.0

func Luhn(s string) bool

Luhn reports a non-empty all-digit string whose Luhn checksum is valid; any non-digit, including separators, fails.

func MAC

func MAC(s string) bool

MAC reports a hardware address in any format net.ParseMAC accepts (colon, hyphen or dot separated; 48-bit, 64-bit or 20-byte InfiniBand).

func Semver added in v0.2.0

func Semver(s string) bool

Semver reports a semantic version per semver.org, including pre-release and build metadata; a leading "v" fails.

func TimeZone added in v0.2.0

func TimeZone(s string) bool

TimeZone reports an IANA time zone name known to time.LoadLocation ("UTC", "Asia/Shanghai"), so the result depends on the host's zone database or the embedded tzdata. "Local" and the empty name are rejected as environment-dependent. Results are cached per name.

func ULID added in v0.2.0

func ULID(s string) bool

ULID reports a 26-character Crockford base32 ULID in either case; the timestamp overflow bound of the first character is not checked.

func URI

func URI(s string) bool

URI reports an absolute URI: a scheme is required but, unlike URL, a host is not, so "mailto:a@b" and "urn:isbn:123" pass.

func URL

func URL(s string) bool

URL reports an absolute URL with both a scheme and a host, as parsed by url.ParseRequestURI ("https://example.com/x"); relative references and host-less URIs such as "mailto:a@b" fail. Use URI for the latter.

func UUID

func UUID(s string) bool

UUID reports the 8-4-4-4-12 hexadecimal form in either case, of any version; braces, URN prefixes and the bare 32-digit form fail.

Types

This section is empty.

Jump to

Keyboard shortcuts

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