I am currently developing a Zapier integration where there is an input field that requires a date from the user. I need this date to match the format “2020-09-18T15:30” exactly. If the input does not adhere to this format, I want to display a message indicating that the input is invalid.
I attempted to implement a regex check for this purpose, but it has not been effective. Here is the code I used:
const activityEditableFields = async (z, bundle) => {
if (bundle.inputData.dueDate) {
(/
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}Z/
.test(`${bundle.inputData.dueDate}`))
}
}
In this case, the field is named dueDate, and I want to validate its format. Unfortunately, the Zap does not display any error messages when incorrect dates are entered. Can someone help me figure out what I’m doing wrong?
you’re missing the actual error throwing part. add throw new Error('invalid date format') after the regex test fails. also, your regex has a z at the end but your example format doesn’t - fix that too.
Your regex test runs but you’re not doing anything with the result. That’s the main problem - you test it but don’t act on whether it passes or fails. In Zapier CLI, you need to throw an error when validation fails or it’ll just keep going and confuse users.
I’ve hit this same issue before. You need proper error handling plus the right regex pattern. Your current regex has a trailing ‘Z’ that doesn’t match what you’re trying to validate. And wrapping the test in parentheses without assigning it or using it in an if statement just throws the result away.
For date validation in Zapier, I’d skip the perform function entirely. Add validation right to your field definition with required and helpText, plus a custom validator function. Way better UX since it catches problems before the zap runs instead of failing mid-execution.
You’re running the test but not doing anything with the result. You need to actually throw an error when validation fails. Try this:
const activityEditableFields = async (z, bundle) => {
if (bundle.inputData.dueDate) {
const datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/;
if (!datePattern.test(bundle.inputData.dueDate)) {
throw new z.errors.HaltedError('Date must be in format YYYY-MM-DDTHH:MM');
}
}
}
Your regex had a trailing Z that doesn’t match your expected format. Also, z.errors.HaltedError works better in Zapier than generic Error objects - cleaner error handling. The caret and dollar signs make sure the entire string matches exactly.