Is it possible to validate the size and type of input=file in HTML5?

Yes, it is possible to validate the size and type of input type = “file”. Use jQuery to get the desired result −

<!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;

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 25-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started