Validate the size of input=file in HTML5?

JavascriptWeb DevelopmentFront End Scripts

You can try to run the following code to validate the size of input type file:

<!DOCTYPE html>
         <script src=""></script>
         <form >
            <input type="file" id="myfile" data-max-size="32154" />
            <input type="submit"/>
                  var val = true;
                  if(typeof this.files[0] !== 'undefined'){
                     var max = parseInt($(this).attr('max-size'),10),
                     mySize = this.files[0].size;
                     val = max > mySize;
                     return val;
               return val;
Updated on 29-Jan-2020 10:49:35