Before starting the sixth part I will recommend you to please go through the below parts,
- AngularJS Validation In MVC - Part One
- AngularJS Validation In MVC - Part Two
- AngularJS Validation In MVC - Part Three
- AngularJS Validation In MVC - Part Four
- AngularJS Validation In MVC - Part Five
This part will teach you how to,
- How to call custom validation in angular JS
Custom validation usually required when you want to call external functionality from your code and validate the control. For example you might need to do database validation for verifying the user name. For this you need following things to be done.
Initial requirement is reference
<script src="~/Scripts/angular.js"></script>
- Add directive in your angular js function. This function will verify is your control value is from specific string names. You may modify by giving service call.
- app.directive('myDirective', function()
- {
- return
- {
- require: 'ngModel',
- link: function(scope, element, attr, mCtrl)
- {
- function myValidation(value)
- {
- var myarr = ["India", "ind", "india", "Ind"];
- if (myarr.indexOf(value) > -1)
- {
- mCtrl.$setValidity('charE', true);
- } else
- {
- mCtrl.$setValidity('charE', false);
- }
- return value;
- }
- mCtrl.$parsers.push(myValidation);
- }
- };
- });
- Refer your directive in the control to be validate as below way,
- <input name="Country" ng-model="Country" required my-directive>
- Give Proper message where you want to give validation message,
- <li ng-show="myForm.Country.$invalid">Country should be India/Ind.</li>
- Run the program and you will find then validation working as below

Hope you will enjoy displaying validation summary box.

Raja TPosted May 12, 2016, 12:21 AM
Nice, Thanks for sharing
Kuppurasu NagarajPosted May 11, 2016, 9:13 AM
Nice Sharing..
Anu VPosted May 11, 2016, 1:22 AM
Nice
Shridhar SharmaPosted May 11, 2016, 1:03 AM
nice share
Pankaj Kumar ChoudharyPosted May 10, 2016, 12:40 PM
Nice One Sir..........
Neeraj KumarPosted May 10, 2016, 11:39 AM
Good Article...
Sonu ChaudharyPosted May 10, 2016, 7:32 AM
good one
Debasis SahaPosted May 10, 2016, 12:47 AM
Good One..
Ajay GandhiPosted May 9, 2016, 11:40 PM
Thanks everyone
Thiruppathi RPosted May 9, 2016, 11:15 PM
Nice Info..
Vignesh ManiPosted May 9, 2016, 5:57 PM
Nice one