I am using this code to find blank spaces in a file name in a SharePoint list attachment.
function PreSaveAction() {
var attachment;
var filename = "";
var fileNameSpecialCharacters = new RegExp('\\s', 'g');
try {
attachment = document.getElementById("idAttachmentsTable").getElementsByTagName("span")[0].firstChild;
filename = attachment.data;
} catch (e) {}
if (fileNameSpecialCharacters.test(filename)) {
alert("Please remove the special characters and white spaces from file attachment name.");
return false;
} else {
return true;
}
}
In IE it checks white space in the ‘whole path’ instead of the file name. In all other browsers it works fine,
Can anyone help me to make this code check the file name only, not the whole path?
Split off the file name from the path name. Then test the file name only.