Skip to content

FrenchSoftware/libvalidator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord

libvalidator

A simple Go library for form validation

Installation

go get github.com/frenchsoftware/libvalidator

Example

package main

import (
	"net/http"
	"github.com/frenchsoftware/libvalidator/validator"
)

func handleSignup(w http.ResponseWriter, r *http.Request) {
	v := validator.New(
		validator.Field("email").Required().IsValidEmail().MaxLength(255),
		validator.Field("name").Required().MinLength(1).MaxLength(255),
	)

	ok, errs := v.Validate(r)

	if !ok {
		// errs.Has("email") - check if field has errors
		// errs.Get("email") - get first error message
		renderFormWithErrors(w, errs)
		return
	}

	// Process valid form data
	processSignup(r)
}

License

MIT License

About

A simple Go library for form validation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages