I want to validate a cron expression using javascript. Here is a library that deals with cron expression http://bunkat.github.io/later/
From the documentation I am not able to found how to validate a cron expression. Whatever I am passing to var cronSched = later.parse.cron('$%#'); Its always filling cronSched with an object. So How to get some true/false value for a cron expression?
Had the same needs and this tool appears to handle the job:
https://github.com/harrisiirak/cron-parser
Here is an solution, using lodash:
try{
var validacao = cronParse.parseString(valor.cron);
if (_.isEmpty(validacao.errors)){
return true;
}
throw "Invalid Cron!"
}
catch(ex){
return false;
}
Then you can test your return value to fullfill your needs. Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With