AngularJS performs form validation on the client-side. AngularJS monitors the state of the form and input fields (input, text-area, select), and notify the user about the current state. AngularJS also holds information about whether the input fields have been touched, modified, or not.
Form input fields have the following states:
- $untouched: It shows that field has not been touched yet.
- $touched: It shows that field has been touched.
- $pristine: It represents that the field has not been modified yet.
- $dirty: It illustrates that the field has been modified.
- $invalid:It specifies that the field content is not valid.
- $valid:It specifies that the field content is valid.
These all are the properties of the input field which can be either true or false.
Forms have the following states:
- $pristine: It represents that the fields has not been modified yet.
- $dirty: It illustrates that one or more fields has been modified.
- $invalid:It specifies that the form content is not valid.
- $valid:It specifies that the form content is valid.
- $submitted:It specifies that the form is submitted.
- Form required attribute with a custom validation message in HTML5
- How to create form validation by using only HTML ?
- Form validation using jQuery Poppa Plugin
- AngularJS | ng-form Directive
- How to get form input value using AngularJS ?
- Laravel | Validation Rules
- ES6 | Validation
- How to Display Validation Message for Radio Buttons with Inline Images using Bootstrap 4 ?
- What is Unobtrusive Validation in jQuery?
- Design a form component which takes input from its user and displays a form
- AngularJS | ng-show Directive
- AngularJS | currency Filter
- How to convert string into a number using AngularJS ?
- Introduction to AngularJS
- AngularJS | Factory Method
- AngularJS | ng-init Directive
These all are the properties of the form which can be either true or false.
This states can be used to show meaningful messages to the user.
Custom validation:To create your own validation function add a new directive to your application, and deal with the validation inside a function with certain specified arguments.
Example 2:Create your own directive, containing a custom validation function, and refer to it by using app-directive. The field will only be valid if the value is greater than or equal to 18.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.