let d = new Date();
let nextValidDate = d.getDate() + "." + (d.getMonth() + 1) + "." + d.getFullYear();
$(document).on("blur change", ".datepicker", function () {
nextValidDate = $(this).datepicker("getDate");
});
$(document).on('focus', '.datepicker',
function () {
$(this).datepicker({
numberOfMonths: 1,
firstDay: 1,
changeMonth: true,
changeYear: true,
dateFormat: 'dd.mm.yy',
minDate: nextValidDate
});
$(this).datepicker('show');
});
$(document).on('blur', '.datepicker', function () {
if ($(this).val().length >= 2) {
parseInputDate(this);
}
});
function parseInputDate(elm) {
var currDate = new Date(),
monDt = (('0'+currDate.getMonth()+1).slice(-2)+('0'+currDate.getDate()).slice(-2)), // get current month+date to compare
inputVal = $(elm).val().match(/\d{2}/gi); // split date components into array of [dd,mm,yy,yy]
// another date validation, by comparing parameters and date object result
var isValidDate = function(yyyy,mm,dd) {
var dt = new Date(yyyy,parseInt(mm,10)-1,dd);
return (dt.getFullYear()+'-'+('0'+(dt.getMonth()+1)).slice(-2)+'-'+('0'+dt.getDate()).slice(-2)) == yyyy+'-'+mm+'-'+dd;
}
if (inputVal!=null && inputVal.length>=2) {
var year = currDate.getFullYear();
if (monDt>(inputVal[1]+inputVal[0])) year++;
// generate formatted text based on date component count
// add date validation to catch invalid dates using (new Date('yyyy-mm-dd')).getTime() which will return NaN on invalid date
var result = (inputVal.length==2 && isValidDate(year,inputVal[1],inputVal[0]) && inputVal[0]+'.'+inputVal[1]+'.'+year) ||
(inputVal.length==3 && isValidDate('20'+inputVal[2],inputVal[1],inputVal[0]) && inputVal[0]+'.'+inputVal[1]+'.20'+inputVal[2]) ||
(inputVal.length==4 && isValidDate(inputVal[2]+inputVal[3],inputVal[1],inputVal[0]) &&...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.