I have to format a date in an input textbox in javascript or angular, and I am facing an issue in my code.
HTML:
<input type="text" class="form-control" name="dateOfBirth" ng-model="dob" placeholder="Birthday(MM/DD/YYYY)" ng-required="true" ng-change="change()" maxlength="10" ng-maxlength="10" dob-format>
JS:
vm.change = function (e) {
if (vm.dob) {
var dobLen = vm.dob.length;
if (dobLen === 2 || dobLen === 5)
vm.dob = vm.dob + "/";
}
};
If I type "6"(month) instead of "06", it must automatically change to "06", here I am facing an issue where the forward slash will come when I type two letters and the backspace is not working. So anyone please help me.
Any help would be appreciated.
Date.parseon the whole string and then use angular filters to format the date