在MOSS 2007的list中,我們使用自訂頁面的方式來使用附件控制項功能,發現對於附件名稱的合法性效驗功能丟失了。
方法1:
<script src="/_layouts/STYLES/jquery-1.4.4.min.js" type="text/javascript"></script>function ValidateData() { var isValid = true; $("input[name^='fileupload']").each(function() { if ($(this).val() != "") { alert(GetShortFileName($(this).val())); } }); return isValid;}function GetShortFileName(fileName){ var splits = fileName.split("\\"); var shortFileName = splits [splits.length-1]; return shortFileName;}
方法2:
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 from the file attachment name.");return false; } else { return true; } }