Validation

Cron Expression

Validate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^(\\*|([0-5]?\\d))\\s+(\\*|([01]?\\d|2[0-3]))\\s+(\\*|([1-9]|[12]\\d|3[01]))\\s+(\\*|([1-9]|1[0-2]))\\s+(\\*|[0-7])$", "");
const input = "0 9 * * 1";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^(\*|([0-5]?\d))\s+(\*|([01]?\d|2[0-3]))\s+(\*|([1-9]|[12]\d|3[01]))\s+(\*|([1-9]|1[0-2]))\s+(\*|[0-7])$

Raw source: ^(\*|([0-5]?\d))\s+(\*|([01]?\d|2[0-3]))\s+(\*|([1-9]|[12]\d|3[01]))\s+(\*|([1-9]|1[0-2]))\s+(\*|[0-7])$

How it works

Each of the five fields is validated against its allowed range. Minute: 0–59. Hour: 0–23. Day-of-month: 1–31. Month: 1–12. Day-of-week: 0–7 (0 and 7 both mean Sunday). Each field also accepts * for any value.

Examples

Input

0 9 * * 1

Matches

  • 0 9 * * 1

Input

*/15 * * * *

No match

—

Input

60 25 * * *

No match

—

Common use cases

  • •CI/CD pipeline schedule validation
  • •Scheduled job configuration forms
  • •DevOps automation tooling
  • •Serverless function trigger validation

Related patterns