Mi duda es con respecto a como unir 2 funciones (Tamaño máximo de un archivo y tipo de archivo) para formar una sola función y llamarla desde un input.
function checkFileSize() {
var CV = document.getElementById("CV");
var files = CV.files;
if (files.length > 0) {
if (files[0].size > 1024 * 1024 * 2) { // Validar la restricción
CV.setCustomValidity("El archivo seleccionado no debe ser mayor a 2MB");
return;
}
}
CV.setCustomValidity("");
}
function fileValidation() {
var fileInput = document.getElementById("CV");
var filePath = fileInput.value;
var allowedExtensions = /(.pdf|.odt|.doc|.docx)$/i;
if (!allowedExtensions.exec(filePath)) {
alert('Solo se aceptan archivos en formato Pdf(.pdf), Word(.doc/.docx), OpenDocument(.odt)');
fileInput.value = '';
return false;
}
Intente hacer esto:
function dosfunciones() {
checkFileSize();
fileValidation();
}
Para después llamarlo en en input por el onchange="checkFileSize(); fileValidation();
pero no me lee mas que una de las funciones.