How to validate a file upload field using Javascript/jquery

前端 未结 6 954
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 03:54

How can I validate if the user has selected a file to upload?

Edit: bumped

6条回答
  •  我在风中等你
    2021-02-07 04:27

    Simple and powerful way(dynamic validation)

    place formats in array like "image/*"

    var upload=document.getElementById("upload");
    var array=["video/mp4","image/png"];
    upload.accept=array;
    upload.addEventListener("change",()=>{
    
    console.log(upload.value)
    })

提交回复
热议问题