Execute
<!DOCTYPE html> <html> <head> <title>Wikitechy AngularJS Tutorials</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> </head> <style> input.ng-invalid { background-color:white; } input.ng-valid { background-color:orange; } </style> <body> <h3>AngularJS input directive</h3> <form ng-app="myApp" ng-controller="inputCtrl" name="myform" ng-submit="submitForm(myform.$valid)" novalidate> <input type="text" name="number" ng-model="number" required ng-minlength="3" ng-change="changefun()" ng-pattern="/^[0-9]+$/" ng-maxlength="6"> <span style="color:red" ng-show="myform.number.$dirty && myform.number.$invalid"> <span ng-show="myform.number.$error.required">Phone is required.</span> <span ng-show="myform.number.$error.pattern">Pattern does not match</span> <span ng-show="myform.number.$error.minlength">Phone must be max 6 char</span> </span> <p>{{mychange}}</p> <input type="submit" value="submit" ng-click="Submit()" /> </form> <script> var app = angular.module("myApp", []); app.controller("inputCtrl", function($scope ) { $scope.changefun = function() { $scope.mychange="text changed"; }; </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.