Skip to content

Instantly share code, notes, and snippets.

@rendro
Last active December 18, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rendro/5728259 to your computer and use it in GitHub Desktop.
Save rendro/5728259 to your computer and use it in GitHub Desktop.
VALIDATE ALL THE DATES!!!!
var leadingZeros = function(num, length) {
length = length || 2;
num = String(num);
while (num.length < length) {
num = "0" + num;
}
return num;
};
var validDate = function(value) {
if (!!value && value.match(/^(\d{2}\.){2}\d{4}$/g)) {
var parts = ko.utils.arrayMap(value.split('.'), function(part) { return parseInt(part, 10); }),
inputDate = new Date(parts[2], parts[1] - 1, parts[0]),
gernatedDate = [leadingZeros(inputDate.getDate()), leadingZeros(inputDate.getMonth() + 1), inputDate.getFullYear()].join('.');
return +inputDate > +(new Date()) && value === gernatedDate;
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment