Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Numbers And Strings
Objects And Array
AngularJS VS JavaScript
Controllers in Files
Load the Library
AngularJS Directives
Repeating Directive
AngularJS Facts
Create Directives
Restrict Directive
Custom Filter
AngularJS Services
AngularJS Service 2
AngularJS Tables
Select Option
Select Option 2
AngularJS Forms
Form Validation
Validation CSS
Validation Example
AngularJS API
AngularJS $http
AngularJS Database
AngularJS HTML DOM
AngularJS Events
Custom Validation
AngularJS Tutorial
AngularJS Introduction
Angular init Directive
AngularJS Expressions 1
AngularJS Applications
AngularJS Expressions 2
Angular CSS Properties
AngularJS JSON
AngularJS Modules
Controller Basic
Add a Directive
Model Directive
Validate Inputs
CSS Classes
Data Binding
AngularJS Controller
AngularJS Scope
Root of Scope
AngularJS Filters
 


  

 
Custom Validation
Question Posted on 24 Apr 2020

Home >> Tutorial >> AngularJS >> Custom Validation


Custom Validation
In angularJS we have power to create our own validation function . It is little bit tricky. We need to add a new directive to our application. And to deal with the validation in function we need to do a certain specified arguments.
In below example we have created our own directive and we name this is my-directive. Here we will check if input field has a character in it if it is there then we will get "True" else it is "False".


AngularJS Custom Validation
In Above example below are the most usefull points which helps you to understand the example:-

(1)In new directive will be referred to by using the attribute my-directive.

(2)Here in the JavaScript we start adding a new directive named as myDirective.

(3)Name should be choosen safely like camel case name myDirective. But when invoking this we must use "-" separated name as my-directive.

(4)When retrun object where we specify that we require ngModel which is the ngModelController.

(5)We Make a linking function which takes arguments and the fourth argument, mCtrl, is the ngModelController.

(6)We specify a function, and is named myValidation, which takes one argument, this argument is the value of the input element.

(7)Test if the value contains the letter "a", and set the validity of the model controller to either true or false.

(8)At last, mCtrl.$parsers.push(myValidation); will add the myValidation function to an array of other functions, which will be executed every time the input value changes.





Other Important Questions
Numbers And Strings
Objects And Array
AngularJS VS JavaScript
Controllers in Files
Load the Library







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |