我只需要上传.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>发布于 2013-12-03 09:05:15
尝尝这个
^.+\.(?:(?:[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您也可以检查这里的大梁
https://stackoverflow.com/questions/20346715
复制相似问题