AngularJS Form Validations

AngularJS reduces our work in setting the validations for input types with few built-in directives. It can also execute the fundamental input types of HTML5 such as email, text, number, etc.

The form elements can be binded by their property values using the ng-model directive. There are few built-in directives that are very helpful in validating or submitting the form. These built-in directives can also be modified as desired. Various AngularJS events can also be used with the HTML5 elements.

  • ng-submit : Used to submit the form data.

  • novalidate : Used to block or disable the built-in browser validations.

  • required : This attribute can be used if the form field requires a value (mandatory) to be entered.

  • minlength, maxlength : To set the input range.

  • $dirty : Indicates that some value has been entered in the field. User interacted with the fields.

  • $invalid : Indicates that the values entered are incorrect or invalid.

  • $pristine : Indicates that the user didn’t interact with the field yet.

  • $valid : Indicates that the values entered are valid.

  • $error : Indicates and shows the actual error.

$dirty, $invalid, $pristine, $valid directives can also be used as CSS classes to style the input field. Their class names are ng-dirty, ng-invalid, ng-pristine, ng-valid respectively.

To print the validity of the form, use this statement above the input type submit – {{ formName.$valid }}

REFERENCE

https://docs.angularjs.org/guide/forms

Previous
Previous

Angular ui-select

Next
Next

AngularJS Filters