How To Validate Max File Size Using Javascript

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

Hello Friends,

In this post i will help you to validate max file size using javascript, Many time we have requirement to check validation of maximum size of file before uploading in server.So i have created post how to validate max file size using javascript,

I have created one blade file and check file size using 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


Recommended Post
Featured Post

Follow us
facebooklogo github instagram twitter