Last active
February 3, 2019 14:35
-
-
Save x-strong/5378739 to your computer and use it in GitHub Desktop.
"yyyy-MM-dd HH:mm:ss" format datetime regular expression.exactly match Feb‘s date no mater leap year or not. “2013-04-12 22:50:00”格式的时间正则表达式,平年闰年2月日期亦完全匹配正确。
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
//yyyy-MM-dd HH:mm:ss | |
var dateTimeRegex=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/; | |
//yyyy-MM-dd | |
var dateRegex=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/; | |
//yyyyMMdd | |
var dateRegex2 = /^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)0229)$/; | |
//HH:mm:ss | |
var timeRegex=/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@x-strong Can I ask the license of this code? I'd like to include it in one of my applications.