
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Validate the size of input=file in HTML5?
You can try to run the following code to validate the size of input type file:
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> <form > <input type="file" id="myfile" data-max-size="32154" /> <input type="submit"/> </form> <script> $(function(){ $('form').submit(function(){ var val = true; $('input[type=file][data-max-size]').each(function(){ 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; }); }); </script> </body> </html>
- Related Articles
- Is it possible to validate the size and type of input=file in HTML5?
- How not to validate HTML5 input with required attribute
- Remember and Repopulate File Input in HTML5
- Client Checking file size using HTML5
- How can I validate EditText input in Android?
- Input type URL in HTML5
- Change the size of Bootstrap input groups
- HTML5 & JavaScript: resolution or size of
- HTML5 Input type “number” in Firefox
- What are input elements in HTML5
- IE supports the HTML5 File API
- How can I validate EditText input in Android using Kotlin?
- Autocomplete text input for HTML5?
- HTML5 Canvas Font Size Based on Canvas Size
- input type week really exist in HTML5?

Advertisements