AngularJs check if date is valid
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.result1 = ''; $scope.result2 = ''; $scope.dateModel = new Date(); $scope.chackDate1 = function() { var d = new Date($scope.dateModel); if(angular.isDate(d)){ $scope.result1= true; }else{ $scope.result1= false; } } $scope.chackDate2 = function() { var d1 = "01-03-2016"; // will return false as d1 is string. If you convert it to date it will give true. if(angular.isDate(d1)){ $scope.result2= true; }else{ $scope.result2= false; } } }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <input type="text" ng-model="dateModel" /><br> <button ng-click ="chackDate1()" >Check Date</button> <br> Result = {{result1}}<br> <button ng-click ="chackDate2()" >Check Date</button> <br> Result = {{result2}} </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.result1 = ''; $scope.result2 = ''; $scope.dateModel = new Date(); $scope.chackDate1 = function() { var d = new Date($scope.dateModel); if(angular.isDate(d)){ $scope.result1= true; }else{ $scope.result1= false; } } $scope.chackDate2 = function() { var d1 = "01-03-2016"; // will return false as d1 is string. If you convert it to date it will give true. if(angular.isDate(d1)){ $scope.result2= true; }else{ $scope.result2= false; } } }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <input type="text" ng-model="dateModel" /><br> <button ng-click ="chackDate1()" >Check Date</button> <br> Result = {{result1}}<br> <button ng-click ="chackDate2()" >Check Date</button> <br> Result = {{result2}} </div> </div> </body> </html>
Copyrights@tutorialsplane.com