How To Validate Max File Size Using Javascript

Websolutionstuff | Aug-03-2020 | Categories : Laravel PHP jQuery

This article will show us how to validate max file size using javascript. Many times we have a requirement to check the validation of the maximum file size before uploading to the server. So, I have created a post on max file upload validation jquery.

So, let's see file upload validation in javascript or file upload size validation using jquery.

I have created one blade file and checked file size using the if condition in jquery.

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>File upload size validation in javascript -</title>
  <link href="" rel="stylesheet">
  <script src=""></script>  
  <h3 style="text-align: center;">File upload size validation in javascript -</h3>
  <div class="col-md-6 col-md-offset-5"><br>
  <input type="file" name="file"  id="filesizecheck"><br>
  <span id="error-message" class="validation-error-label"></span>
<script type="text/javascript">
      for(var i=0; i< $(this).get(0).files.length; ++i){
        var file1 = $(this).get(0).files[i].size;
          var file_size = $(this).get(0).files[i].size;
          if(file_size > 2000000){
            $('#error-message').html("File upload size is larger than 2MB");


And you will get output like this.

file upload size validation


You might also like:

Recommended Post
Featured Post
How To Remove index.php From URL In Laravel 9
How To Remove index.php From U...

If you're a developer, you're likely to have frustration with "index.php" cluttering up your website&#...

Read More


How to Convert PDF to Image in Laravel 10
How to Convert PDF to Image in...

Greetings, Laravel enthusiasts! Today, let's unravel a common challenge in web development – converting PDFs t...

Read More


How to Convert Excel File into JSON in Javascript
How to Convert Excel File into...

Today in this small post i will show you how to convert excel file into json in javascript. Many time we have requi...

Read More


How to Upgrade PHP 8.0 to 8.1 in Ubuntu
How to Upgrade PHP 8.0 to 8.1...

Hey there! I recently needed to upgrade my PHP version from 8.0 to the latest 8.1 on my Ubuntu server. It's a smart...

Read More