Provides utility functions that plug into the validate option of Payload fields. Developers pass conditions with custom messages, or use ready-made validators for regex, email, URL and IP address. It also includes a helper to run valibot checks inside a condition.
Easy validation handlers for Payload CMS collection's fields
Installation
npm i payload-field-validators4
Stars
0
Forks
0
Open Issues
1 years ago
Last Updated
0
Weekly Downloads
v0.2.3
npm Version
20.1 KB
Unpacked Size
1
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/956096125-root)<a href="https://payloaddirectory.dev/plugins/956096125-root"><img src="https://payloaddirectory.dev/badge/956096125-root.svg" alt="Payload Directory"></a>README
Easy validation handlers for Payload CMS collection's fields
Assuming we have a Collection
export default MyCollection: CollectionConfig = {
// other fields..
{
name: "number_field",
type: "number",
},
{
name: "text_field",
type: "text",
}
// other fields..
}
We can add a validator to TextField:
{
// other configs..
validate: (value: any) =>
validateField({
condition: value.length < 100,
})
}
Similarly, we can add a validator to NumberField:
{
// other configs..
validate: (value: any) =>
validateField({
condition: value > 100,
})
}
The default message will be "Invalid input"
message param:{
// other field's configs..
name: "percentage_usage",
validate: (value: any) => validateField({
condition: value > 20 and value < 50,
message: "percentage must be between 20 to 50 %"
})
}
NumberField and for each case to show appropriate message:{
name: "grade",
type: "number",
required: true,
validate: (value: any) => validateField([
{
condition: value >= 55,
message: "Grade must be at minimum 55"
},
{
condition: typeof value === "number" && Number.isInteger(value),
message: "Grade must be an Integer"
}
])
},
You can use form validation libraries like valibot/zod/vest to write more concise conditions
using valibotCheck utility
// import valibot
import * as v from "valibot";
//....
{
name: "grade",
type: "number",
required: true,
validate: (value: any) => validateField({
condition: valibotCheck(v.pipe(v.number(), v.integer(), v.minValue(55), value)),
message: "Grade must be an Integer, minimum 55"
})
},
TextFieldconst onlyLettersRegex = /^[a-zA-Z0-9]+$/;
export default MyCollection: CollectionConfig = {
{
name: "name",
type: "text",
admin: {
readOnly: false,
hidden: false
},
validate: (value: any) => validateRegex(
onlyLettersRegex,
value,
"Name must not contain special characters" // (optional error message)
),
required: true
}
TextFieldexport default MyCollection: CollectionConfig = {
{
name: "email",
type: "text",
validate: (value: any) => validateEmail(value, optionaLmessage), // --> add this line
required: true
}
TextFieldexport default MyCollection: CollectionConfig = {
{
name: "url",
type: "text",
admin: {
readOnly: false,
hidden: false
},
validate: (value: any) => validateUrl(valuem optionaLmessage), // --> add this line
required: true
}
TextFieldexport default MyCollection: CollectionConfig = {
{
name: "website_url",
type: "text",
admin: {
readOnly: false,
hidden: false
},
validate: (value: any) => validateIPAddress(value), // --> add this line
required: true
}
Topics
payload plugin tooling
Shared lint, format, TypeScript, build, test and CI config for building Payload plugins
650/wk0v4
payload dev tools
Floating dev toolbar, /dev pages and an app snapshot for AI agents in Payload projects on Next.js
560/wk18v3
payload arch skill
Claude Code skill enforcing a route, controller, service and store architecture in Payload projects
322v?
payload plugin template
Starter template for building Payload v3 plugins with a dev app, tests and Docker support
197v3
plugin template
Blank starter template for building a Payload plugin in TypeScript
052v2
form builder
Let admin editors build and manage forms and submissions directly in the Payload admin panel
10074.5k/wk45.4kv3