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 11, 2016, 8:21 PM EDT
Nice, Thanks for sharing
Kuppurasu NagarajTOP 100Posted May 11, 2016, 5:13 AM EDT
Nice Sharing..
Anu VPosted May 10, 2016, 9:22 PM EDT
Nice
Shridhar SharmaPosted May 10, 2016, 9:03 PM EDT
nice share
Pankaj Kumar ChoudharyTOP 100Posted May 10, 2016, 8:40 AM EDT
Nice One Sir..........
Neeraj KumarPosted May 10, 2016, 7:39 AM EDT
Good Article...
Sonu ChaudharyPosted May 10, 2016, 3:32 AM EDT
good one
Debasis SahaTOP 100Posted May 9, 2016, 8:47 PM EDT
Good One..
Ajay GandhiPosted May 9, 2016, 7:40 PM EDT
Thanks everyone
Thiruppathi RPosted May 9, 2016, 7:15 PM EDT
Nice Info..
Vignesh ManiTOP 100Posted May 9, 2016, 1:57 PM EDT
Nice one