1

I'm using Kendo datepicker to allow the user to enter the date. However I want to allow the user to type only date in particular format, i.e., MM/DD/YYYY

<input kendo-date-picker placeholder="from" class="form-control" id="fromDate"  ng-keydown="validateDateEntered()" />

Now when a user enters something in the input field, I do the validation like:

$scope.validateDateEntered= function () {
                   $("#fromDate").kendoDatePicker({
                       format: "MM/dd/yyyy"
                   });
               }

Doing this still allows a user to type invalid characters. Just want to understand how can I allow user to only enter date in MM/DD/YYYY format and discard everything else.

halfer
  • 19,824
  • 17
  • 99
  • 186
Abhishek
  • 1,974
  • 5
  • 31
  • 67

1 Answers1

0

(Posted on behalf of the OP).

After some research, I've found the solution as:

<input kendo-date-picker placeholder="from" class="form-control" id="fromDate" onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 47' />
halfer
  • 19,824
  • 17
  • 99
  • 186