<script type="text/javascript">
function CheckFile(str)
{
var strRegex = "(.jpg|.JPG|.gif|.GIF)$"; //用于验证图片扩展名的正则表达式
var re=new RegExp(strRegex);
if (re.test(str)){
return (true);
}
else{
alert("禁止的文件扩展名");
return (false);
}
}
</script>
<input id="File1" type="file" onchange="CheckFile(this.value);" />
<br />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" onchange="CheckFile(this.value);" />
<br />
<br />
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload2" ErrorMessage="必须是 jpg或者gif文件" ValidationExpression="^(([a-zA-Z]:)|(//{2}/w+)/$?)(//(/w[/w].*))(.jpg|.JPG|.gif|.GIF)$">
</asp:RegularExpressionValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="上传" />