首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >只允许Jpg和Jpeg文件。

只允许Jpg和Jpeg文件。
EN

Stack Overflow用户
提问于 2013-12-03 08:59:49
回答 1查看 426关注 0票数 1

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

下面是带有验证的文件上传控件:

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-03 09:05:15

尝尝这个

代码语言:javascript
运行
复制
^.+\.(?:(?:[jJ][pP][eE][gG])|(?:[jJ][pP][gG]))$

更多描述

代码语言:javascript
运行
复制
^           = 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

您也可以检查这里的大梁

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20346715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档