AngularJS Form Validation (very comprehensive)

Source: Internet
Author: User

Build a NG form

Novalidate= "Novalidate"

The Action property cannot be in 2.form. Submitted to Ng-submit for processing

3. Each input must have a ng-model, preferably a name to facilitate reference. And then use require or ng-minlength to work.

<form name= "form" novalidate= "Novalidate" >  <label name= "email" >your email</label>  < Input type= "email" name= "email" ng-model= "email" placeholder= "email Address"/></form>

NG provides validation by default

To verify that you have entered text, simply add required to the label:

<input type= "text" ng-model= "User.Name" required/>

Verify that at least enter {number} characters, using the directive ng-minlength= "{Number}":

<input type= "text" ng-model= "User.Name" ng-minlength= "5"/>

Verify that you enter {number} characters and use the instruction Ng-maxlength= "{number}":

<input type= "text" ng-model= "User.Name" ng-maxlength= "/>"

Make sure the input matches a regular expression, using the directive ng-pattern= "/pattern/":

<input type= "text" ng-model= "User.Name" ng-pattern= "/a-za-z/"/>

Verify that input is an email and set the Type property of input to email:

<input type= "Email" name= "email" ng-model= "User.email"/>

Verify that the input is a number, set the Type property of input to #:

<input type= "number" name= "number" ng-model= "User.age"/>

Verify that the input is a URL, set the Type property of input to URL

<input type= "url" name= "homepage" ng-model= "User.weburl"/>

AngularJS Form Validation (very comprehensive)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.