<script>
function check()
{
var filepath = path.valuefilepath = filepath.substring(filepath.lastIndexOf('.') + 1, filepath.length);
if(filepath != 'jpg' && filepath != 'gif') alert("只能上?JPG或GIF格式的?片");
}
</script>
<input type=file name=path onpropertychange="check()">
<script>
function ck(obj)
{
if(obj.value.length > 0)
{
var af = "jpg,gif,png,zip,rar,txt,htm";
if(eval("with(obj.value)if(!/" + af.split(",").join("|") + "/ig.test(substring(lastIndexOf('.')+1,length)))1;"))
{
alert("Allowed file types:\n" + af);
obj.createTextRange().execCommand('delete');
}
}
}
</script>
<form>
<input type=file name=path onpropertychange="ck(this)"/></form>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="請選擇操作腳本檔!" SetFocusOnError="True">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="只能上傳尾碼為.txt的文件!" SetFocusOnError="True" ValidationExpression="^.*[\.txt]{1}$">*</asp:RegularExpressionValidator>
一、二為腳本實現,第三個為正則運算式實現。
本文來源於Woody的鳥窩(Woody's Blog) http://www.smartgz.com,
原文地址:http://www.smartgz.com/blog/Article/1188.asp
沒有留言:
張貼留言