Skip to content

Instantly share code, notes, and snippets.

@shiro01
Last active June 5, 2018 06:01
Show Gist options
  • Save shiro01/60715652c67fe8436476795a1448f7a2 to your computer and use it in GitHub Desktop.
Save shiro01/60715652c67fe8436476795a1448f7a2 to your computer and use it in GitHub Desktop.
datetime format validation.
datetimeStart = "2018-01-01 00:00:00";
datetimeEnd = "2018-01-01 23:59:59";
function validation(datetimeStart, datetimeEnd) {
if (!/^\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}$/.test(datetimeStart)) {
return false;
} else if (!/^\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}$/.test(datetimeEnd)) {
return false;
} else if (datetimeStart >= datetimeEnd) { // 0埋めの場合、文字列のまま比較可能
return false;
} else {
return true;
}
}
validation(datetimeStart, datetimeEnd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment