Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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])?)*$")
Use the regexp.MustCompile() function to parse a pattern and compile a regular expression for sanity checking the format of an email address. This returns a *regexp.Regexp object, or panics in the event of an error. Doing this once at runtime, and storing the compiled regular expression object in a variable, is more performant than re-compiling the pattern with every request.
Functions ¶
This section is empty.
Types ¶
type Form ¶
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 ¶
Define a New function to initialize a custom Form struct. Notice that this takes the form data as the parameter?
func (*Form) MatchesPattern ¶
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 ¶
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 ¶
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 ¶
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.