gmeka
gmeka

Reputation: 4289

Jquery date validation for invalid date entry

I'm implementing jQuery date picker. which can pick date from calendar as well as keyboard entry. When it is picked from the calendar it's working fine.

<input type="text" id="date" />

<script>
  $('#date').datepicker ({
    dateFormat: 'mm/dd/yy'
  }).on("change", function(){
    alert("You Entered: "+($(this).datepicker('getdate')));
  })

Problem is when I enter, lets say 02/31/2014. which is invalid. I wanted to set a custom message to the user that $ is invalid.

But Jquery is passing on today's date for wrong entries. How can I get exact value of user entry (02/31/2014)?

Upvotes: 2

Views: 4683

Answers (1)

gmeka
gmeka

Reputation: 4289

When using the getdate method of jQuery, Its automatically setting to today's date for an invalid date (not sure why it is lke this in Jquery).

alert("You Entered: "+($(this).datepicker('getdate')));

instead of this use this

alert("You Entered: "+($("#date").val());

Update: Fiddle Demo

Upvotes: 1

Related Questions