validations

package module
v0.0.0-...-9fa71a7 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 8 Imported by: 0

README

fnkit/validations

A Go module for common data validation and type conversion utilities. Import as:

import "github.com/kishankumarhs/fnkit/validations"

Validators

  • IsEmail(s string) bool — Validates email addresses.
  • IsURL(s string) bool — Validates URLs.
  • IsUUID(s string) bool — Validates UUIDs (v1-v5).
  • IsAlpha(s string) bool — Letters only (Unicode).
  • IsNumeric(s string) bool — Digits only (Unicode).
  • IsAlnum(s string) bool — Letters or digits (Unicode).
  • IsHex(s string) bool — Hexadecimal string.
  • IsIP(s string) bool — IPv4 or IPv6 address.
  • IsLower(s string) bool — All letters lowercase.
  • IsUpper(s string) bool — All letters uppercase.
  • IsASCII(s string) bool — All runes are ASCII.
  • IsPrintable(s string) bool — All runes are printable.
  • IsPhone(s string) bool — Simple phone number check.
  • IsCreditCard(s string) bool — Credit card number (Luhn check).

Type Conversion

  • ToString(v any) string — Converts any value to string.
  • ToInt(v any) (int, bool) — Converts to int if possible.
  • ToFloat64(v any) (float64, bool) — Converts to float64 if possible.

Example Usage

import "github.com/kishankumarhs/fnkit/validations"

validations.IsEmail("foo@bar.com") // true
validations.IsUUID("123e4567-e89b-12d3-a456-426614174000") // true
validations.ToInt("42") // 42, true

Tests

All functions are covered by unit tests in validate_test.go.


MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsASCII

func IsASCII(s string) bool

IsASCII returns true if all runes in s are ASCII.

func IsAlnum

func IsAlnum(s string) bool

IsAlnum returns true if s contains only letters or digits (Unicode).

func IsAlpha

func IsAlpha(s string) bool

IsAlpha returns true if s contains only letters (Unicode).

func IsCreditCard

func IsCreditCard(s string) bool

IsCreditCard returns true if s looks like a credit card number (Luhn check, 13-19 digits).

func IsEmail

func IsEmail(s string) bool

IsEmail returns true if s is a valid email address.

func IsHex

func IsHex(s string) bool

IsHex returns true if s is a valid hexadecimal string (0-9, a-f, A-F).

func IsIP

func IsIP(s string) bool

IsIP returns true if s is a valid IPv4 or IPv6 address.

func IsLower

func IsLower(s string) bool

IsLower returns true if all letters in s are lowercase.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric returns true if s contains only digits (Unicode).

func IsPhone

func IsPhone(s string) bool

IsPhone returns true if s looks like a phone number (simple, digits, optional +, -, spaces).

func IsPrintable

func IsPrintable(s string) bool

IsPrintable returns true if all runes in s are printable.

func IsURL

func IsURL(s string) bool

IsURL returns true if s is a valid URL.

func IsUUID

func IsUUID(s string) bool

IsUUID returns true if s is a valid UUID (version 1-5).

func IsUpper

func IsUpper(s string) bool

IsUpper returns true if all letters in s are uppercase.

func ToFloat64

func ToFloat64(v any) (float64, bool)

ToFloat64 tries to convert any value to a float64. Returns (value, true) if successful.

func ToInt

func ToInt(v any) (int, bool)

ToInt tries to convert any value to an int. Returns (value, true) if successful.

func ToString

func ToString(v any) string

ToString converts any value to a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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