标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:Detecting an “invalid date” Date instance in JavaScript41 answersI want to validate if the date input to a function is a valid date.I have the following HTML markup<div class="input-group"><span class="input-group-addon"><i class="fa fa-calendar"></i> Check in</span><input id="checkinner" type="date" onchange="datechange(this)" class="form-control" data-inputmask="'alias': 'dd/mm/yyyy'" placeholder="Enter checkin date of birth"></div>And the following is my function in javascriptfunction datechange(element) {if (element.value.IsValidDate()){//code }}Appreciate the love and help!


What is the definition of Valid Data in your case?

2019年08月19日46分50秒

stackoverflow.com/questions/1353684/…

2019年08月19日46分50秒

dd/mm/yyyy or dd-mm-yyyy both are valid date format. Splitting a date string with / is not a complete answer to this question.

2019年08月19日46分50秒

According to developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…, "It is not recommended to use Date.parse as until ES5, parsing of strings was entirely implementation dependent. There are still many differences in how different hosts parse date strings, therefore date strings should be manually parsed (a library can help if many different formats are to be accommodated)."

2019年08月19日46分50秒