AngularJS Form Validation

Source: Internet
Author: User

Form validation through ANGULARJS requires setting the Novalidate property in the form

The Novalidate property is not required in the app, but you need to use it in the AngularJS form to override the standard HTML5 validation.

Before form validation and validation rules need to be set to form, and input to the Name property, in order to validate when the label gets to the validation

Validation rules: Both are Boolean

(Specific validation rules can be written with regular expressions in input Add Ng-pattern property)

$dirty: The form has been filled in records, whether modified

$valid: Fields that are filled in are legal and validated

$invalid: The entry is not legal, failed

$pristine: The form has no content and has not been modified

$submitted: Have you submitted

For example:

<form ng-app="myApp" ng-controller="Validatectrl"
Name="MyForm" novalidate>

<P> Email:
<InputType="Email"Name="Email"Ng-model="Email"Required>
<Spanstyle="Color:red"ng-show=>
  <span ng-show= "Myform.email. $error. Required" > mailbox is required. </span>
  <span ng-show= "Myform.email. $error. Email" Span class= "HIGHGT" >> illegal mailbox. </span>
  </span>
</p< Span class= "highgt" >>

</FORM>

$error object: Generated when validation does not pass, contains all failed validation rules

$untouched    boolean  have never been clicked/touched     
$touched   boolean     has lost focus
$pristine   boolean     has never been modified
$dirty   Whether the boolean  has been modified
$valid    boolean   If all validations are validated through
$invalid     Boolean      Verify that the
$name   string  The value of the table cell Name property

AngularJS Form Validation

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.