Cron expression validator

disasterkid picture disasterkid · Oct 9, 2014 · Viewed 8.5k times · Source

I would like to have user-defined cron expressions in my program. Are there are validators for cron expressions so that the user cannot insert an invalid cron code?

N.B. I think the cron expression on Quartz.Net has a slight different format than the one used in UNIX. I would like to the Quartz version of it.

Answer

Kraiss picture Kraiss · Oct 9, 2014

UNIX Cron expressions and Quartz ones are differents. Simply,

  • In Unix
    • (minute, hour, day, month, day_of_week, year)
  • In Quartz
    • (second, minute, hour, day, month, day_of_week, year)

You can use this to know if a Cron expression is correct.

EDIT : Look at CronExpression.ValidateExpression method.