Skip to content

Instantly share code, notes, and snippets.

@carlosdlf
Created March 2, 2017 21:28
Show Gist options
  • Save carlosdlf/a5d34b9488e66d5d07950a75ecba013f to your computer and use it in GitHub Desktop.
Save carlosdlf/a5d34b9488e66d5d07950a75ecba013f to your computer and use it in GitHub Desktop.
<script>
function checkFile(fieldObj)
{
var FileName = fieldObj.value;
var FileExt = FileName.substr(FileName.lastIndexOf('.')+1);
var FileSize = fieldObj.files[0].size;
var FileSizeMB = (FileSize/2097152).toFixed(2);
// aca van las extensiones validas
if ( (FileExt != "pdf" && FileExt != "doc" && FileExt != "docx") || FileSize>2097152) // 2097152 es el tamaño de 2 megas
{
var error = "Tipo Archivo : "+ FileExt+"\n\n";
error += "Tamaño Archivo: " + FileSizeMB + " MB \n\n";
error += "No se permiten archivos de mas de 2 MB.\n\n";
alert(error);
return false;
}
return true;
}
</script>
<input type="file" name="confirm" id="confirm" onchange="checkFile(this)">
<input type="file" name="approveletter" id="approveletter" onchange="checkFile(this)">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment