https://github.com/hollodotme/crontab-validator
A validator for crontab expressions
https://github.com/hollodotme/crontab-validator
crontab crontab-syntax expression php validator
Last synced: 8 months ago
JSON representation
A validator for crontab expressions
- Host: GitHub
- URL: https://github.com/hollodotme/crontab-validator
- Owner: hollodotme
- License: mit
- Created: 2016-08-29T20:00:11.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-08-04T20:20:50.000Z (almost 7 years ago)
- Last Synced: 2025-07-30T14:28:06.591Z (10 months ago)
- Topics: crontab, crontab-syntax, expression, php, validator
- Language: PHP
- Homepage:
- Size: 39.1 KB
- Stars: 10
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/hollodotme/crontab-validator)
[](https://coveralls.io/github/hollodotme/crontab-validator?branch=master)
[](https://packagist.org/packages/hollodotme/crontab-validator)
[](https://packagist.org/packages/hollodotme/crontab-validator)
[](https://packagist.org/packages/hollodotme/crontab-validator)
# CrontabValidator
A validator for crontab expressions.
Sources used to determine the allowed expressions:
* https://crontab.guru/
* https://en.wikipedia.org/wiki/Cron
## Features
* Validation of crontab expressions like 6,21,36,51 7-23/1 * FEB-NOV/2 *.
## Requirements
* PHP >= 7.1
## Installation
```
composer require "hollodotme/crontab-validator"
```
## Usage
### Boolean validation
```php
isExpressionValid( '6,21,36,51 7-23/1 * FEB-NOV/2 *' ) )
{
echo 'Expression is valid.';
}
else
{
echo 'Expression is invalid.';
}
```
### Guarding
```php
All fine, execution continues
$validator->guardExpressionIsValid( '6,21,36,51 7-23/1 * FEB-NOV/2 *' );
# => This will raise an InvalidExpressionException
$validator->guardExpressionIsValid( 'this is not a valid interval' );
}
catch ( InvalidExpressionException $e )
{
echo $e->getMessage();
}
```
**Prints:**
Invalid crontab expression: "this is not a valid interval"
---
Feedback and contributions welcome!