forms

package
v0.0.0-...-a0af51b Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 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])?)*$")

EmailRX validates an email

Functions

This section is empty.

Types

type Form

type Form struct {
	url.Values
	Errors errors
}

Form 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

New initializes 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)

MatchesPattern method checks 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)

MaxLength method checks 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)

MinLength method checks 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)

PermittedValues method checks 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)

Required method checks 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

Valid method 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