Skip to main content

Posts

Showing posts with the label file size validation using javascript

Javascript File Size Validation Example

Hi Dev, Today, i will learn how to check file size validation using Javascript. we will check file size validation using Javascript. I can check file size validation using Javascript.Now, we get the file size on the image change event and after. I will check the file size, if file size greater than 2mb then it will return the error messages otherwise return the success message.ill explain to you how to check file (Image) size validation before upload the file using Javascript. solution function OnFileValidation() { var image = document.getElementById("image"); if (typeof (image.files) != "undefined") { var size = parseFloat(image.files[0].size / (1024 * 1024)).toFixed(2); if(size > 2) { alert('Please select image size less than 2 MB'); }else{ alert('success'); } } else { alert("This browser does not support HTML5."); } } So you can see here our example. Ex