forms

package
v0.0.0-...-d3dc9c4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmailRX = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

Functions

This section is empty.

Types

type Form

type Form struct {
	url.Values
	Errors errors
}

Create a custom Form struct, which anonymously embeds a url.Values object (to hold the form data) and an Errors field to hold any validation errors for the form data.

func New

func New(data url.Values) *Form

Define a New function to initialize a custom Form struct. Notice that this takes the form data as the parameter?

func (*Form) MatchesPattern

func (f *Form) MatchesPattern(field string, pattern *regexp.Regexp)

Implement a MatchesPattern method to check that a specific field in the form matches a regular expression. If the check fails then add the appropriate message to the form errors.

func (*Form) MaxLength

func (f *Form) MaxLength(field string, d int)

Implement a MaxLength method to check that a specific field in the form contains a maximum number of characters. If the check fails then add the appropriate message to the form errors.

func (*Form) MinLength

func (f *Form) MinLength(field string, d int)

Implement a MinLength method to check that a specific field in the form contains a minimum number of characters. If the check fails then add the appropriate message to the form errors.

func (*Form) PermittedValues

func (f *Form) PermittedValues(field string, opts ...string)

Implement a PermittedValues method to check that a specific field in the form matches one of a set of specific permitted values. If the check fails then add the appropriate message to the form errors.

func (*Form) Required

func (f *Form) Required(fields ...string)

Implement a Required method to check that specific fields in the form data are present and not blank. If any fields fail this check, add the appropriate message to the form errors.

func (*Form) Valid

func (f *Form) Valid() bool

Implement a Valid method which returns true if there are no errors.

Jump to

Keyboard shortcuts

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