Last active
June 17, 2024 08:07
-
-
Save memochou1993/f94a1059292244ce69015d969418c0dc to your computer and use it in GitHub Desktop.
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
function validateCronExpression(input) { | |
const segment = '(\\*|(T|\\*\\/[1-9][0-9]*|(T)(-(T))?)(,(T|\\*\\/[1-9][0-9]*|(T)(-(T))?))*)'; | |
const minute = segment.replaceAll('T', '[0-5]?[0-9]'); | |
const hour = segment.replaceAll('T', '[0-1]?[0-9]|2[0-3]'); | |
const dayOfMonth = segment.replaceAll('T', '[1-9]|[12][0-9]|3[01]'); | |
const month = segment.replaceAll('T', '[1-9]|1[0-2]'); | |
const dayOfWeek = segment.replaceAll('T', '[0-6]'); | |
const cronRegex = new RegExp(`^${minute}\\s+${hour}\\s+${dayOfMonth}\\s+${month}\\s+${dayOfWeek}$`); | |
return cronRegex.test(input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment