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
Formvalidation.html
app.js
Formvalidation.html
<!DOCTYPE html>
<html>
<head>
<!-- CSS -->
<!-- load bootstrap -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body { padding-top:30px; }
</style>
<!-- JS -->
<!-- load angular -->
<script src="js/anguler_1.2.js"></script>
<script src="js/app.js"></script>
</head>
<!-- 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="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">You name is required.</p>
</div>
<!-- USERNAME -->
<div class="form-group">
<label>Username</label>
<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>
</div>
<!-- EMAIL -->
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" ng-model="email">.
<p ng-show="userForm.email.$invalid && !userForm.email.$pristine" class="help-block">Enter a valid email.</p>
</div>
<!-- SUBMIT BUTTON -->
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div><!-- col-sm-8 -->
</div><!-- /container -->
</body>
</html>
A few central stops to notice here
novalidate
is used to disable browser's native form validationThe ngModel directive provides the two-way data-binding by synchronizing the model to the view, as well as view to the model
app.js
//app.js
// 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")
}
};
});
Thanks for giving the useful post, I gain more details from your blog. Good job and keep it up...
ReplyDeleteTableau Training in Chennai
Tableau Course in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Social Media Marketing Courses in Chennai
Pega Training in Chennai
Excel Training in Chennai
Tableau Training in Chennai
Tableau Course in Chennai
Great blog. Inspired me a lot. Thank you.
ReplyDeleteSoftware Testing Course in Madurai
Software Testing Classes in Madurai
Software Testing Training in Madurai
Software Testing Course in Coimbatore
Best Software Testing Training Institute in Coimbatore
Software Testing Institute in Coimbatore
Well written Blog, I really enjoy reading your blog. this info will be helpful for me. Thanks for sharing.
ReplyDeleteccna Training in Chennai
ccna institute in Chennai
Angularjs Training in Chennai
PHP Training in Chennai
Web Designing Course in Chennai
ccna course in chennai
ccna training in chennai
Got to know something new reading your blog and thanks for sharing this with us. Great reading your blog.
ReplyDeleteSpoken English Class in Thiruvanmiyur
Spoken English Classes in Adyar
Spoken English Classes in T-Nagar
Spoken English Classes in Vadapalani
Spoken English Classes in Porur
Spoken English Classes in Anna Nagar
Spoken English Classes in Chennai Anna Nagar
Spoken English Classes in Perambur
Spoken English Classes in Anna Nagar West
Thanks for sharing worthy information. This is really helpful for learning. Keep doing more.
ReplyDeleteEnglish Speaking Classes in Mulund
English Speaking Classes in Mulund West
English Speaking Course in Mulund
English Speaking Course in Mulund East
English Speaking Course in Mulund West
Best English Speaking Classes in Mulund West
English Speaking Classes Mulund
Awesome post which i have seen.I read your blog everything is helpful and effective.
ReplyDeleteAngularJS Training in Chennai
AngularJS Course in Chennai
AngularJS Training in Anna Nagar
AngularJS Training in T Nagar
AngularJS Training in OMR
Web Designing Course in chennai
Web Designing training in chennai
Web Designing Training in Velachery
I read awesome post after a long time.I am very satisfied with your way of writing.Expect the next post in the upcoming days.
ReplyDeleteAngularJS Training in OMR
Web designing Training in Anna Nagar
AngularJS Training in Tambaram
Web Designing Training in OMR
AngularJS Training in Porur
Web Designing Training in Porur
AngularJS Training in Velachery
Web designing Training in T Nagar
unbiased home reviews
ReplyDeletevumoo
ReplyDeletewhatsapp groups
ReplyDeletexmovies8
ReplyDeleteimo for pc
ReplyDeleteimo for pc
ReplyDelete