I have the following script in which I use a jquery to validate a regular expression that filters the names of the files to upload:
$(document).on('change', "input[type='file']", function() {
var validaFile = $("input[type='file']").val();
if (validaFile != '') {
var regex = RegExp('^[a-zA-Z0-9-_.]+$');
if (!regex.test(validaFile)) {
$("input[type='file']").val('');
alert("O nome deste arquivo é inválido. Por favor renomeie o arquivo.");
return;
}
}
});
The issue is that the code worked with Firefox Developer, but it does not work on Chrome and Edge. Regardless of the file I enter it will always give invalid filename.