Angular Form Validation – A Beginner’s Guide

What is Angular Validation?

Angular Forms and controls in AngularJS give validation services and inform users of invalid input. AngularJS provides us with different information about a form or its inputs and is applied to a form and inputs.
To track error following terms are used:

  • $dirty− states that value has been altered.
  • $error− states the exact error.
  • $invalid− states that value entered is invalid.

Watch this Full Stack Web Development Course Video:

Video Thumbnail

e.g.
<!DOCTYPE html><br>
<html><br>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script><br>
<body><br>
<h1>Example of Validation</h1><br>
<form ng-app="myApp" ng-controller="validateCtrl"<br>
name="intellipaatForm" novalidate><br>
<p>Username:<br><br>
<input type="text" name="username" ng-model="username" required><br>
<span style="color:red" ng-show="intellipaatForm.username.$dirty && intellipaatForm.username.$invalid"><br>
<span ng-show="intellipaatForm.username.$error.required">Username is required.</span><br>
</span><br>
</p><br>
<p>Email:<br><br>
<input type="email" name="email" ng-model="email" required><br>
<span style="color:red" ng-show="intellipaatForm.email.$dirty && intellipaatForm.email.$invalid"><br>
<span ng-show="intellipaatForm.email.$error.required">Email is required.</span><br>
<span ng-show="intellipaatForm.email.$error.email">Invalid email address.</span><br>
</span><br>
</p><br>
<p><br>
<input type="submit"<br>
ng-disabled="intellipaatForm.username.$dirty && intellipaatForm.username.$invalid ||<br>
intellipaatForm.email.$dirty && intellipaatForm.email.$invalid"><br>
</p><br>
</form><br>
<script><br>
var app = angular.module('myApp', []);<br>
app.controller('validateCtrl', function($scope) {<br>
$scope.username = 'abc';<br>
$scope.email = '[email protected]';<br>
});<br>
</script><br>
</body><br>
</html><br>

Output

Angular JS Expert

o18
If you remove the name of the id from the text box it shows the following output:
o19

About the Author

Software Developer | Technical Research Analyst Lead | Full Stack & Cloud Systems

Ayaan Alam is a skilled Software Developer and Technical Research Analyst Lead with 2 years of professional experience in Java, Python, and C++. With expertise in full-stack development, system design, and cloud computing, he consistently delivers high-quality, scalable solutions. Known for producing accurate and insightful technical content, Ayaan contributes valuable knowledge to the developer community.