AngularJS Form Validation


Angularjs providing  form validation facility, so that the user can be notified of invalid input.  This provides a safer user experience, because the user receives instant feedback on how to rectify the mistake. Maintain in brain that while client-side validation plays an important part in providing a good user experience, it can easily be circumvented and thus can not be trusted. Server-side validation is still necessary for a secure application.

We need 2 files



 <!DOCTYPE html>  
   <!-- CSS -->  
   <!-- load bootstrap -->  
   <link rel="stylesheet" href="css/bootstrap.min.css">   
        body      { padding-top:30px; }  
   <!-- JS -->  
   <!-- load angular -->  
   <script src="js/anguler_1.2.js"></script>   
   <script src="js/app.js"></script>  
 <!-- apply angular app and controller to our body -->  
 <body ng-app="formValidationApp" ng-controller="formController">  
 <div class="container">  
 <div class="col-sm-8 col-sm-offset-2">  
   <!-- PAGE HEADER -->  
   <div class="page-header"><h3>AngularJS Form Validation with HTML5</h3></div>  
   <!-- FORM -->  
   <!-- novalidate is used to disable browser's native form validation -->  
   <form name="userForm" ng-submit="submitForm(userForm.$valid)" novalidate>   
     <!-- NAME -->  
     <div class="form-group">  
       <label>Name *</label>  
       <input type="text" name="name" class="form-control" ng-model="name" required>  
       <p ng-show="$invalid && !$pristine" class="help-block">You name is required.</p>  
     <!-- USERNAME -->  
     <div class="form-group">  
       <input type="text" name="username" class="form-control" ng-model="user.username" ng-minlength="3" ng-maxlength="8" required>  
       <p ng-show="userForm.username.$error.minlength" class="help-block">Username is too short.</p>  
       <p ng-show="userForm.username.$error.maxlength" class="help-block">Username is too long.</p>  
       <p ng-show="userForm.username.$invalid && !userForm.username.$pristine" class="help-block">Please enter Username</p>  
     <!-- EMAIL -->  
     <div class="form-group">  
       <input type="email" name="email" class="form-control" ng-model="email">.  
       <p ng-show="$invalid && !$pristine" class="help-block">Enter a valid email.</p>  
     <!-- SUBMIT BUTTON -->  
     <button type="submit" class="btn btn-primary">Submit</button>  
 </div><!-- col-sm-8 -->  
 </div><!-- /container -->  

A few central stops to notice here

novalidate is used to disable browser's native form validation

The ngModel directive provides the two-way data-binding by synchronizing the model to the view, as well as view to the model


 // create angular app  
 var formValidationApp = angular.module('formValidationApp', []);  
 // create angular controller  
 formValidationApp.controller('formController', function($scope) {  
   // function to submit the form after all validation has occurred                 
   $scope.submitForm = function(isValid) {  
     // check to make sure the form is completely valid  
     if (isValid) {  
       alert('our form is amazing');  
     } else {  
       alert("All values are not filled Please check")  


  1. This post is so interactive and informative.keep update more information...
    hadoop training in velachery
    Big data training in chennai

  2. This post is so interactive and informative.keep update more information...
    Angularjs training in anna nagar
    Angularjs Training in Chennai

  3. Great post. keep sharing such a worthy information.
    Hadoop Training in Chennai

  4. Much obliged for sharing this brilliant substance. its extremely fascinating. Numerous web journals I see these days don't actually give whatever pulls in others however the manner in which you have plainly clarified everything it's truly awesome. There are loads of posts But your method of Writing is so Good and Knowledgeable. continue to post such helpful data and view my site too...
    How to make a paper airplane | Origami paper plane | Boomerang Airplane | how to make a eagle paper airplane | Best paper airplane design for distance and speed | Nakamura lock paper airplane
    Eagle paper plane | Zazoom | Easy Freezy

  5. This will increase the Kingdom’s complete offshore fabrication capability from 30,000 MT to 100,000 MT yearly. The new yards will fabricate and assemble offshore platforms, jackets and structures for subsea pipelines. To tackle the processing challenges of SSEs, one of the key LLNL staff members, Allison Browar, set up a novel CO2 double sided tape laser sintering system with stage heating capability. The staff used the system and efficiently demonstrated the fast densification of low-packing-density Li6.4La3Zr1.4Ta0.6O12 movies.