Cron Expression Validator
Validate cron expressions and see a detailed field-by-field breakdown
Cron expression
minute hour day(month) month day(week)
Field breakdown
*/15(0β59)Expands to: 0, 15, 30, 45
0-6(0β23)Expands to: 0, 1, 2, 3, 4, 5, 6
1,15(1β31)Expands to: 1, 15
*(1β12)Expands to: all (1β12)
1-5(0β6)Expands to: 1, 2, 3, 4, 5
What Is Cron Expression Validation?
Cron expression validation is the process of checking whether a cron string follows the correct syntax rules before it reaches a scheduler. A cron expression uses five space-separated fields (minute, hour, day-of-month, month, day-of-week) to define a recurring schedule. If any field contains an out-of-range value, an invalid operator, or a structural error like the wrong number of fields, the expression will either be rejected by the scheduler at deploy time or silently fail to match any trigger time.
Validating a cron expression online catches errors earlier than deploying to production and waiting for a missed job. Typical mistakes include writing 25 in the hour field (valid range: 0-23), using a step of zero (*/0, which is undefined), reversing range bounds (5-1 instead of 1-5), or adding extra fields that belong to non-standard formats like Quartz. A syntax checker flags these problems instantly and tells you exactly which field is wrong.
Cron validation differs from cron parsing. A parser takes a valid expression and translates it into a human-readable schedule. A validator answers a simpler question: is this expression well-formed? Validate before you parse β there is no point feeding an invalid expression to a scheduler. In CI/CD pipelines, automated cron validation prevents broken schedules from being merged into config files.
Why Use This Cron Validator?
A cron expression has strict syntax rules, and schedulers provide inconsistent error messages when those rules are broken. Some schedulers reject the expression with a cryptic error; others accept it silently and never fire. This validator gives you a clear, field-by-field diagnosis before you deploy.
Cron Validator Use Cases
Common Cron Syntax Errors
The table below lists the most frequent cron expression errors and what causes them. These are the mistakes that crop up repeatedly in production configs and CI/CD pipelines.
| Error type | Example | What went wrong |
|---|---|---|
| Too few fields | 0 9 * * | Missing the day-of-week field. Standard cron requires exactly 5 fields. |
| Too many fields | 0 0 9 * * 1 2026 | Extra fields. Some tools add seconds or year, but standard cron uses 5. |
| Value out of range | 0 25 * * * | Hour field accepts 0-23. Value 25 exceeds the maximum. |
| Invalid step base | 0 0 32/2 * * | Day-of-month starts at 32, which exceeds the 1-31 range. |
| Step of zero | */0 * * * * | Step value must be 1 or greater. Zero creates an infinite loop. |
| Empty field | 0 9 * * 1 | Double space creates an empty field. Each field needs a value. |
| Invalid character | 0 9 * * Mon-Fry | Typo in day name. Use three-letter abbreviations: MON, TUE, WED, THU, FRI, SAT, SUN. |
| Reversed range | 0 9 * * 5-1 | Range end (1) is less than start (5). Write 1-5 or use a list: 5,6,0,1. |
Valid vs. Invalid Cron Expressions
A quick reference of well-formed expressions alongside common mistakes. Use this to sanity-check your expression before pasting it into a scheduler config.
Code Examples
How to validate cron expressions programmatically in JavaScript, Python, Go, and Bash. Each example shows how to catch invalid syntax and extract a meaningful error message.
import { parseExpression } from 'cron-parser';
// Validate a cron expression by attempting to parse it
function validateCron(expr) {
try {
parseExpression(expr);
return { valid: true, error: null };
} catch (err) {
return { valid: false, error: err.message };
}
}
console.log(validateCron('0 9 * * 1-5'));
// β { valid: true, error: null }
console.log(validateCron('0 25 * * *'));
// β { valid: false, error: "Constraint error, got value 25 expected range 0-23" }
// Validate with field-level detail using cron-validator
import { isValidCron } from 'cron-validator';
isValidCron('*/15 * * * *'); // β true
isValidCron('*/15 * * * *', { seconds: true }); // β false (expects 6 fields)
isValidCron('0 0 31 2 *'); // β true (syntactically valid, Feb 31 never fires)from croniter import croniter
# Validate by checking if croniter can parse the expression
def validate_cron(expr: str) -> dict:
if croniter.is_valid(expr):
return {"valid": True, "error": None}
# Get a more specific error message
try:
croniter(expr)
except (ValueError, KeyError) as e:
return {"valid": False, "error": str(e)}
return {"valid": False, "error": "Unknown error"}
print(validate_cron("0 9 * * 1-5"))
# β {'valid': True, 'error': None}
print(validate_cron("0 25 * * *"))
# β {'valid': False, 'error': '...out of range...'}
print(validate_cron("* * *"))
# β {'valid': False, 'error': 'Exactly 5 or 6 columns...'}
# Field-level validation
from crontab import CronTab
cron = CronTab(tab="")
job = cron.new(command="/bin/true")
try:
job.setall("0 9 * * 1-5")
print(job.is_valid()) # β True
except Exception as e:
print(f"Invalid: {e}")package main
import (
"fmt"
"github.com/robfig/cron/v3"
)
// ValidateCron checks whether a 5-field cron expression is syntactically correct
func ValidateCron(expr string) (bool, error) {
parser := cron.NewParser(
cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow,
)
_, err := parser.Parse(expr)
if err != nil {
return false, err
}
return true, nil
}
func main() {
exprs := []string{
"0 9 * * 1-5", // valid
"0 25 * * *", // invalid: hour 25
"*/15 * * * *", // valid
"0 0 32 * *", // invalid: day 32
}
for _, e := range exprs {
ok, err := ValidateCron(e)
if ok {
fmt.Printf("%-20s VALID
", e)
} else {
fmt.Printf("%-20s INVALID: %v
", e, err)
}
}
}#!/bin/bash
# Validate cron syntax using Python one-liner
validate_cron() {
python3 -c "
from croniter import croniter
import sys
expr = sys.argv[1]
if croniter.is_valid(expr):
print(f'VALID: {expr}')
sys.exit(0)
else:
print(f'INVALID: {expr}')
sys.exit(1)
" "$1"
}
validate_cron "0 9 * * 1-5" # β VALID: 0 9 * * 1-5
validate_cron "0 25 * * *" # β INVALID: 0 25 * * *
# Quick regex pre-check (catches field count and obvious issues)
cron_regex='^([0-9*/,-]+\s+){4}[0-9*/,-]+$'
echo "*/5 * * * *" | grep -Eq "$cron_regex" && echo "passes basic check"
echo "* * *" | grep -Eq "$cron_regex" || echo "fails basic check"