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 ¶
- func Base64(s string) bool
- func CIDR(s string) bool
- func CIDRv4(s string) bool
- func CIDRv6(s string) bool
- func CreditCard(s string) bool
- func E164(s string) bool
- func Email(s string) bool
- func FQDN(s string) bool
- func HexColor(s string) bool
- func Hostname(s string) bool
- func IP(s string) bool
- func IPv4(s string) bool
- func IPv6(s string) bool
- func JSON(s string) bool
- func JWT(s string) bool
- func Latitude(s string) bool
- func Longitude(s string) bool
- func Luhn(s string) bool
- func MAC(s string) bool
- func Semver(s string) bool
- func TimeZone(s string) bool
- func ULID(s string) bool
- func URI(s string) bool
- func URL(s string) bool
- func UUID(s string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64 ¶
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
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 CreditCard ¶ added in v0.2.0
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
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 ¶
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
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
HexColor reports a "#"-prefixed CSS hex color with 3, 4, 6 or 8 hex digits, in either case.
func Hostname ¶
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 ¶
IP reports an IPv4 or IPv6 address literal as accepted by net.ParseIP; zone suffixes ("fe80::1%eth0") and CIDR prefixes fail.
func IPv4 ¶
IPv4 reports a dotted-quad IPv4 address; IPv4-mapped IPv6 forms such as "::ffff:1.2.3.4" fail.
func IPv6 ¶
IPv6 reports an IPv6 address literal, including IPv4-mapped forms such as "::ffff:1.2.3.4".
func JWT ¶ added in v0.2.0
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
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
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
Luhn reports a non-empty all-digit string whose Luhn checksum is valid; any non-digit, including separators, fails.
func MAC ¶
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
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
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
ULID reports a 26-character Crockford base32 ULID in either case; the timestamp overflow bound of the first character is not checked.
func URI ¶
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 ¶
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.
Types ¶
This section is empty.