Last active
June 5, 2018 06:01
-
-
Save shiro01/60715652c67fe8436476795a1448f7a2 to your computer and use it in GitHub Desktop.
datetime format validation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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