利用asp.net正则验证控件验证图片文件格式
<label> 选择图片</label><asp:FileUpload ID="FileUpload1" runat="server" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1" Display="None" ErrorMessage="只能选择jpg,gif,png,jpeg,bmp格式图片" ValidationExpression=".+\.[J|j][P|p][G|g]$|.+\.[J|j][P|p][E|e][G|g]$|.+\.[G|g][I|i][F|f]$|.+\.[P|p][N|n][G|g]$|.+\.[B|b][M|m][P|p]$" ValidationGroup="YZ"></asp:RegularExpressionValidator> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="YZ" /> <asp:Button ID="Button1" runat="server" Text="确定" CssClass="Btn" ValidationGroup="YZ" />
效果图