Prev Demo
AngularJS
>
Input Validation Advance
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <style> .ng-valid{ border:4px double green; } .ng-invalid { border: 4px double red; } </style> <script> var app = angular.module("app", []); app.controller("InputController", function ($scope) { $scope.InputValue = "Type here"; $scope.ValidationError = function (item) { if (item.$dirty && item.$error.required) { return "This text box is mandatory !"; } else { return ""; } }; }); </script> <div ng-app="app" ng-controller="InputController"> <form name="myForm" action="~/Views/Forms/Checkbox.cshtml" method="post"> <div style="padding:10px;"> <input type="text" name="txt" ng-model="InputValue" ng-minlength="5" ng-maxlength="20" required /> <span ng-show="myForm.txt.$invalid" style="color:red;">{{ ValidationError(myForm.txt) }}</span> <input type="submit" value="Submit" /> <hr /> <p><b>Is Required:</b> {{ !!myForm.$error.required}}</p> <hr /> <p><b>Is Textbox Invalid:</b> {{ myForm.txt.$invalid}}</p> <p><b>Text box Error:</b> {{myForm.txt.$error}}</p> <hr /> <p><b>Is Form Valid:</b> {{ myForm.$valid}}</p> <p><b>Form Error:</b> {{myForm.$error}}</p> </div> </form> </div> </body> </html>
Note: We DO NOT save your trial code in our database.
Output