Skip to content

Instantly share code, notes, and snippets.

@istvanp
Created February 21, 2010 08:05
Show Gist options
  • Save istvanp/310203 to your computer and use it in GitHub Desktop.
Save istvanp/310203 to your computer and use it in GitHub Desktop.
Cron expression syntax check (excluding special operators except for * and /)
<?php
$cron = "*/5 * * * * *";
$result = preg_match(
"/(\*|[0-5]?[0-9]|\*\/[0-9]+)\s+"
."(\*|1?[0-9]|2[0-3]|\*\/[0-9]+)\s+"
."(\*|[1-2]?[0-9]|3[0-1]|\*\/[0-9]+)\s+"
."(\*|[0-9]|1[0-2]|\*\/[0-9]+|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+"
."(\*\/[0-9]+|\*|[0-7]|sun|mon|tue|wed|thu|fri|sat)\s*"
."(\*\/[0-9]+|\*|[0-9]+)?/i", $cron, $matches);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment