Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

validate file size in js

function validateSize(input) {
  const fileSize = input.files[0].size / 1024 / 1024; // in MiB
  if (fileSize > 2) {
    alert('File size exceeds 2 MiB');
    // $(file).val(''); //for clearing with Jquery
  } else {
    // Proceed further
  }
}

<input onchange="validateSize(this)" type="file">
Comment

PREVIOUS NEXT
Code Example
Javascript :: loop json object android java 
Javascript :: disable split screen react native 
Javascript :: unpack array into variables javascript 
Javascript :: alert ok with link 
Javascript :: jquery datepicker change date format 
Javascript :: get everything between two characters regex 
Javascript :: get all rooms socket.io 
Javascript :: jsconfig alias 
Javascript :: nodejs readfile 
Javascript :: js date format dd/mm/yyyy 
Javascript :: javascript convert int to float with 2 decimal places 
Javascript :: how to select all elements of type js 
Javascript :: how to select a random value in a json array LUA 
Javascript :: nextjs build failed optimization killed 
Javascript :: Peerjs WebRTC video screen becomes black if not on wifi 
Javascript :: angular readonly/Disabled if value is not null 
Javascript :: set value of radio button jquery 
Javascript :: js strip multiple spaces 
Javascript :: javascript iterate over object 
Javascript :: nodejs check directory exist or not 
Javascript :: javascript select option value onchange 
Javascript :: lua manifest code 
Javascript :: angular amber theme 
Javascript :: js switch case 
Javascript :: javascript discord bot 8 ball command 
Javascript :: json parse stringified array 
Javascript :: load js after ajax 
Javascript :: json schmea typs 
Javascript :: get current url javascript 
Javascript :: javascript get int val 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =