forms

package
v0.0.0-...-440a425 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package forms defines how to create a form and adds validations.

Index

Constants

This section is empty.

Variables

View Source
var EmailRegex = 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
}

Form creates a custom form struct, embeds a url.Values object

func New

func New(data url.Values) *Form

New initializes a form struct

func (*Form) IsEqualString

func (f *Form) IsEqualString(field1 string, field2 string)

IsEqual checks if two string input fields are equal.

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)

MaxLength checks for maximum allowed length of characters.

func (*Form) MinLength

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

MinLength checks for minimum length of characters.

func (*Form) PermittedValues

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

PermittedValues disallows unknown fields.

func (*Form) Required

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

Required checks for empty fields.

func (*Form) SecurePassword

func (f *Form) SecurePassword(field string)

http://www.inanzzz.com/index.php/post/8l1a/validating-user-password-in-golang-requests SecurePassword defines a set of requirements for a password.

func (*Form) Valid

func (f *Form) Valid() bool

Valid returns true if the form has no errors.

func (*Form) ValidUrl

func (f *Form) ValidUrl(field string)

ValidUrl parses a field for a valid URL.

Jump to

Keyboard shortcuts

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