Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

File input size validation


Hi
I used the link below for file validation.
https://preview.keenthemes.com/html/keen/docs/forms/formvalidation/advanced

How can I check the size of the input file as well?

var validator = FormValidation.formValidation(
form,
{
fields: {
'avatar': {
validators: {
notEmpty: {
message: 'Please select an image'
},
file: {
extension: 'jpg,jpeg,png',
type: 'image/jpeg,image/png',
message: 'The selected file is not valid'
},
}
},
},

plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap5({
rowSelector: '.fv-row',
eleInvalidClass: '',
eleValidClass: ''
})
}
}
);


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


File input size validation is a crucial step in ensuring that users upload files within the allowed size limits, preventing performance issues and security risks. By setting maximum file size restrictions in web forms or applications, developers can enhance user experience and system efficiency. Implementing client-side and server-side validation helps avoid unnecessary uploads and reduces server load. Platforms like apkek games also utilize such validations to ensure smooth gameplay experiences by restricting oversized game files, optimizing downloads, and maintaining performance across different devices.



I changed it to

file: {
extension: 'jpg,jpeg,png',
type: 'image/jpeg,image/png',
maxSize:20000,
minSize:200,
message: 'The selected file is not valid'
}
and it worked.



Hi happy,

Glad to know that you figured it out! All the best with your projects!

Regards,
Sean


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(