Validation

Validation example

Build in AngularJS validation

Form and controls provide validation services, so that the user can be notified of invalid input before submitting a form. This provides a better user experience than server-side validation alone because the user gets instant feedback on how to correct the error.

Example on submit:

Please input a username Your username is required to be at least 3 characters Your username cannot be longer than 20 characters
Please input a valid email address
Please input a valid url address (http://website.com)
Please input a password
Please input a valid text (only 'Inspinia' will work)

Example validation while typing:

Please input a username Your username is required to be at least 3 characters Your username cannot be longer than 20 characters
Please input a valid email address
Please input a valid url address (http://website.com)
Please input a password
Overview

Angular provides basic implementation for most common HTML5 input types: (text, number, url, email, date, radio, checkbox), as well as some directives for validation (required, pattern, minlength, maxlength, min, max).

Method Description
required To validate that a form input has been filled out
ng-minlength Makes the element require a given minimum length.
ng-maxlength Makes the element require a given maxmimum length.
ng-pattern To ensure that an input matches a regex pattern
type="email" Makes the element require a valid email
type="url" Makes the element require a valid url
type="number" Makes the element require a decimal number.