Skip to content

Instantly share code, notes, and snippets.

@joshycube
Created September 30, 2016 15:48
Show Gist options
  • Save joshycube/2a35aa15ebdd34f0f45368750acf7d69 to your computer and use it in GitHub Desktop.
Save joshycube/2a35aa15ebdd34f0f45368750acf7d69 to your computer and use it in GitHub Desktop.
Date object's default day
function createDateString(day, month, year) {
return year + '-' + month + '-' + day;
}
function validateDate(dateStr) {
var ourDate = new Date(dateStr);
if(/(Invalid)/.test(ourDate)) {
return false;
}
return true;
}
var firstDate = createDateString('01', '01', '1990');
console.log(validateDate(firstDate));
var secondDate = createDateString('', '01', '1990');
console.log(validateDate(secondDate));
var thirdDate = createDateString(null, '01', '1990');
console.log(validateDate(thirdDate));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment