我正在尝试验证上传文件的扩展名,无论其是jpg还是png。还包括扩展名为JPG,jPg等的扩展名。我有一个解决方案,但它丑陋且效率低下。
ValidationExpression="^.*.(jpg|jpG|jPg|jPG|Jpg|JpG|JPg|JPG|png|pnG|pNg|pNG|Png|PnG|PNg|PNG)$"
有效,但不切实际。
我已按照建议的here尝试过ValidationExpression="^.+(?i:.jpg|.png)$"
,但这导致验证程序无法验证。它使任何类型的文件都可以通过验证。如何在验证器中集成不区分大小写的?i
?
<asp:RegularExpressionValidator
ErrorMessage='Image file must be in "jpg" or "png" format'
ControlToValidate="ImageFileUpload"
ValidationExpression="^.*\.(jpg|jpG|jPg|jPG|Jpg|JpG|JPg|JPG|png|pnG|pNg|pNG|Png|PnG|PNg|PNG)$"
Text="*"
CssClass="errMsg"
runat="server">
</asp:RegularExpressionValidator>