只允许使用Jpg和Jpeg文件

时间:2013-12-03 08:59:50

标签: html asp.net vb.net

我只需要上传.Jpg和.Jpeg文件,但在上传时也允许.gif

这是我的文件上传控件,带有验证:

<td align="left" colspan="3">
 <asp:FileUpload ID="fuAttachment1" runat="server" />
 <asp:RegularExpressionValidator ID="revFile1" runat="server" ControlToValidate="fuAttachment1"
     Enabled="true" ErrorMessage="Invalid File. Please select valid file." ForeColor="Red"
    ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpg|.JPG|.jpeg|.JPEG)$">*
  </asp:RegularExpressionValidator>
</td> </tr>

1 个答案:

答案 0 :(得分:1)

试试这个

^.+\.(?:(?:[jJ][pP][eE][gG])|(?:[jJ][pP][gG]))$

更多说明

^           = beginning of string
.+          = at least one character (any character)
\.          = dot ('.')
(?:pattern) = match the pattern without storing the match)
[dD]        = any character in the set ('d' or 'D')
[xX]?       = any character in the set or none 
              ('x' may be missing so 'doc' or 'docx' are both accepted)
|           = either the previous or the next pattern
$           = end of matched string

您还可以查看regex here