深入浅出SharePoint——在自定义页面中判断附件名字的合法性
在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; } }