Chiran Chiran - 1 year ago 435
AngularJS Question

Angular JS directive for automatically insert slashes '/' in date fields. for Example MM/DD/yyyy

I'm trying to add functionality to input date fields so as when the users enters in digits, slashes "/" get automatically added its in Jquery but I need in Angular JS directive.
Thanks in advance

Answer Source

var app = angular.module('myApp', []);
		  app.controller('appCtrl', ['$scope', function($scope){
		     $scope.change = function(e) {
		     	var numChars = $;
				if(numChars === 2 || numChars === 5){
					var thisVal = $;
					thisVal += '/';
					$ = thisVal;
<script src=""></script>
<div ng-app="myApp" ng-controller="appCtrl">
        <h4>Minimum date</h4>
        <input minlength="0"  maxlength="10" placeholder="DD/MM/YYYY" id="date" ng-change="change()" ng-model="date">
Working example. Please try it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download