Created
January 27, 2022 06:30
-
-
Save HakamRaza/ca01fda2eb616590572d6233bfa747da to your computer and use it in GitHub Desktop.
JS - Validating file types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fileExtArr = ["png", "jpeg", "tft", "bmp", "jpg"]; | |
const maxFileSize = 4194587; | |
function validateUploadedFile(elementId) { | |
let fileElement = getElement(elementId); | |
const ext = fileUploadJson.docType || ""; | |
if (ext == "" || fileExtArr.indexOf(ext.toLowerCase()) < 0) | |
{ | |
fileElement.parentElement.parentElement.nextElementSibling.innerHTML = "Please select a file type (PNG, JPEG, TFT, BPM, JPG, PDF)"; | |
disableLoader(); | |
return false; | |
} else if (parseInt(fileElement.getAttribute('fs')) > maxFileSize) { | |
fileElement.parentElement.parentElement.nextElementSibling.innerHTML = "File size exceeds 4MB. Kindly select a different file"; | |
disableLoader(); | |
return false; | |
} return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment