FILE VALIDATION

Learn how you can validate a file using this library

This type of validation enables you to validate an uploaded file. It is under the group Attributes Validation and they all follow the syntax below;

//syntax
const fileRules = {
FIELD_NAME : {
RULE_TITLE : [VALUE, ERROR_MESSAGE]
}
}

Here are some of the rules needed to validate a file.

ACCEPT

Use this attribute to list out the file extensions allowed for upload.

POSSIBLE VALUES

.png, .jpg, .jpeg


ACCEPT-MIME

Use this attribute to list out the file MIME types allowed for upload. This attribute also supports MIME types with wildcards.

POSSIBLE VALUES 1

image/png, image/jpg, image/jpeg or image/*

We recommend that you use accept-mime attribute to check for the file types of uploaded files, because an end user can rename a file to have an extension outside its original file type.


SIZE

Use this attribute to validate the selected file(s) size. If you provide 5MB, it means that the file selected by the user must be 5MB in size.

It is compatible with both single and multiple file upload inputs.

POSSIBLE VALUES

10MB


MINSIZE

Use this attribute to validate the minimum size of the selected file(s). If you provide 5MB, it means that the file selected by the user must be 5MB in size or more.

It is compatible with both single and multiple file upload inputs.

POSSIBLE VALUES

10MB


MAXSIZE

Use this attribute to validate the maximum size of the selected file(s). If you provide 5MB, it means that the file selected by the user must be 5MB in size or less.

It is compatible with both single and multiple file upload inputs.

POSSIBLE VALUES

10GB

Note that the digital storage supported, ranges from bytes up to petabytes.


FILES

Use this attribute to check the number of files selected by the user. If you provide 5, it means that the user must select 5 files.

This Rule is only supported in multiple file upload input.

POSSIBLE VALUES

5


MINFILES

Use this attribute to check the minimum number of files selected by the user. If you provide 5, it means that the user must select 5 files or more.

This Rule is only supported in multiple file upload input.

POSSIBLE VALUES

10


MAXFILES

Use this attribute to check the maximum number of files selected by the user. If you provide 5, it means that the user must select 5 files or less.

This Rule is only supported in multiple file upload input.

POSSIBLE VALUES

20

Attribute Possible values
accept .png, .jpg, .jpeg
accept-mime image/png, image/jpg, image/jpeg, audio/*
size 20Bytes
minsize 5MB
maxsize 10GB
files 5
minfiles 10
maxfiles 30

Here's an example

//validation rules for file upload
const fileRules = {
profile : {
'R' : "Please upload a profile picture",
'ACCEPT' : ["image/png", "File type is not supported"],
'MAXSIZE' : ["5MB", "Image file should not be greater than 5MB"]
}
}