SIGN IN SIGN UP

fix(cron): anchor regex and accept full cron syntax (#1577)

The cron validator's regex lacked `^...$` anchors, so any string
containing a cron-like substring (e.g. `"random text @daily more text"`,
`"prefix @every 1h suffix"`, `"x 1 2 3 4 5 y"`) was accepted as a valid
cron expression.

Anchoring alone wasn't sufficient — the original field pattern only
recognized plain numeric forms and was getting away with it via
substring matching. Several existing positive test cases (`?`, `L`,
`MON-FRI`, `#`, multi-field expressions with year) only passed because
the regex matched a numeric fragment of the input. The field pattern is
now expanded to accept the documented cron alphabet (`*`, `?`, digits,
letters, `,`, `/`, `-`, `#`, `L`, `W`) while still rejecting bare single
letters like "x" that aren't valid in any cron dialect.

Negative test cases added to lock in the new behavior, with a note
documenting remaining false positives that would require a real cron
parser to reject (out-of-range values, nonsense alphabetic tokens, etc).

- Fixes #1576

## Fixes Or Enhances

**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers

Signed-off-by: Ahmed Kamal <ahmed@ahmedkamal.io>
A
Ahmed Kamal committed
0364541fa467027703223b3d0cace07a667c8302
Parent: 8eb2659
Committed by GitHub <noreply@github.com> on 5/25/2026, 12:16:21 PM