validator

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

README

validator

A simple form validator made with Go.

Installation

go get -u github.com/ezlosswm/validator

Usage

firstname := "ezlos"
if ok := IsEmpty(firstname); !ok {
	log.Printf("(%q) value provided is empty.\n", firstname)
	return
}

a, b := "hello", "world"
if ok := IsMatching(a, b); !ok {
	log.Printf("%s is not equal to %s.\n", a, b)
    return
}

email := "ezlos@example.com"
if ok := CheckEmail(email); !ok {
	log.Printf("%s not a valid email.\n", email)
	return
}

password := "Password123"
if err := CheckLength(password); err != nil {
	log.Println(err)
	return
}

Todo

  • Test for password strenght.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// errors
	TooShortErr = errors.New("input provided is too short")
	TooLongErr  = errors.New("input provided is too long")
)

Functions

func CheckEmail

func CheckEmail(email string) bool

CheckEmail checks if the provided email is valid. If it is valid, CheckEmail returns true.

func CheckLength

func CheckLength(input string) error

CheckLength checks for the length of the input and returns an error if the length of the input is less than 8 or larger than 32.

func IsEmpty

func IsEmpty(input string) bool

IsEmpty will return false if no characters were provided in the input.

func IsMatching

func IsMatching(a, b string) bool

IsMatching checks if the both values provided are equal. If both values are equal, it returns true.

Types

This section is empty.

Jump to

Keyboard shortcuts

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