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> <style> input.ng-pristine { background-color:orange; } input.ng-touched.ng-invalid { background-color:red; } input.ng-touched.ng-valid { background-color:green; } </style> </head> <body> <h3>AngularJS HTML CSS Class Validation </h3> <form ng-app="myApp" ng-controller="inputCtrl" name="myform"> Enter Mobile Number : <input type="text" name="number" ng-model="number" required ng-minlength="10" ng-maxlength="13" ng-pattern="/^[0-9]+$/"> <input type="submit" ng-click="submit()" value="Submit" /> </form> <script> var app = angular.module("myApp", []); app.controller("inputCtrl", function($scope) { $scope.submit = function() { if($scope.myform.$valid) { alert("Form Submitted Successfully!" ); } else { alert("Invalid Form!" ); } }; }); </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.