In SharePoint lists, you are not permitted to upload files which have any kind of special characters in their file name. (For eg: file&.doc cannot be uploaded)
So I have a JavaScript code that validates the file name on submitting the list and creates a dialogue box that tells the user to rename the files before uploading and only then you can proceed.
My issue is, the code only works for 1 document, if more than 1 document is uploaded. it does not validate the second item. I need help so that I can upload n number of items and it validates eac
<Script type="text/javascript">
function PreSaveAction()
{
var attachment;
var filename="";
var fileNameSpecialCharacters = new RegExp("[~#%&*{}<>;?/+|\"]");
try {
attachment = document.getElementById("idAttachmentsTable").getElementsByTagName("span")[0].firstChild;
filename = attachment.data;
}
catch (e) {
}
if (fileNameSpecialCharacters.test(filename)) {
alert("Please remove the special characters like ~#%&*{}<>;?/+|\ from the file attachment name and reattach the file.");
return false;
}
else {
return true;
}
}
</script>