Introduction to cron-expression-validator node-module

what is a cron expression?

Quartz

What is cron-expression-validator?

Installation

npm install cron-expression-validator

What cron-expression-validator do?

  • It provides validation to a given cron expression — returns a boolean value
  • It provides validation and error messages if cron string is invalid — returns Object carrying boolean value and array

Usage

var cronValidator = require('cron-expression-validator');
var isValid = cronValidator.isValidCronExpression("* * * * * ? *"); // isValid -> true
  1. You can pass only cron string to the isValidCronExpression method
  • example 1:
if(cronValidator.isValidCronExpression("* * * * * ? *")) { 
// returns true
// Your code
}
if(cronValidator.isValidCronExpression("* * * * * * *")) {
// returns false
}
  • example 2: with {error: true}
var validObj = cronValidator.isValidCronExpression(
"* * * * 25/2 ? *", {error: true});
  • example 3: with {error: true}
var validObj = cronValidator.isValidCronExpression(
"* * * ? * * 123/555", {error: true});
  • example 4: with {error: false}
var isValid = cronValidator.isValidCronExpression(
"0 0 12 1/2 * ? *", {error: false});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store