Skip to content

file

Validates file input constraints: allowed extensions, file size, and number of files.

Options

OptionTypeDefaultDescription
extensionstringundefinedComma-separated allowed extensions without dots (e.g. "pdf,jpg,png")
maxSizenumberundefinedMaximum file size in bytes
minFilesnumberundefinedMinimum number of files
maxFilesnumberundefinedMaximum number of files
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
.jpg file under 5 MBExtension and size within limits
.jpeg fileMatches allowed extensions

Invalid values

ValueReason
.exe fileExtension not in allowed list
10 MB .jpgExceeds maxSize

Notes

  • Empty string ("") always returns valid: true — validators only run on non-empty values. Combine with notEmpty to require a value.
  • extension is comma-separated without dots: "pdf,jpg,png".
  • maxSize is in bytes: 5 * 1024 * 1024 for 5 MB.

Released under the MIT License.