大家给看下一个验证.rar文件的正则表达式错哪了?

woaiwangxiaoyu 2007-01-10 03:29:29
<asp:RegularExpressionValidator id="FileUpLoadValidator" runat="server"
ErrorMessage="Upload rar and zip only."
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.rar|.RAR|.zip|.ZIP)$"
ControlToValidate="FileUpload1" >

就这么一句话 验证不出来 就是选.rar文件 ,还出提示,怎么回事???
...全文
200 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
woaiwangxiaoyu 2007-01-12
  • 打赏
  • 举报
回复
mobydick兄 能否给个msn 我想当面请求 谢谢
mobydick 2007-01-12
  • 打赏
  • 举报
回复
TextBox中的字符串你复制一下,粘到这里
woaiwangxiaoyu 2007-01-12
  • 打赏
  • 举报
回复
还是不对啊 我还没等提交哪

刚把上传文件的名字加到文本框中就显示了

可快了

明明加的是.rar文件 还是提示出错
woaiwangxiaoyu 2007-01-12
  • 打赏
  • 举报
回复
哦???我试下 有点门
mobydick 2007-01-11
  • 打赏
  • 举报
回复
。。。。。。肯定有个Button点了之后才出提示的吧。
所以,你的验证控件和Button的属性"ValidationGroup"一定要设置成相同的字符串,才会在提交的时候进行验证。
woaiwangxiaoyu 2007-01-11
  • 打赏
  • 举报
回复
无果~~~
woaiwangxiaoyu 2007-01-10
  • 打赏
  • 举报
回复
还是不行 没有正解啊~~~
cancerser 2007-01-10
  • 打赏
  • 举报
回复
try
.RAR → \.RAR
woaiwangxiaoyu 2007-01-10
  • 打赏
  • 举报
回复
2楼的兄弟,你的我试了,但不对

3楼的兄弟,我用的是.net2.0的控件,我就想看看怎么用asp:RegularExpressionValidator

来做,谢谢了.
jacobwc 2007-01-10
  • 打赏
  • 举报
回复

不用这么麻烦的啦
LZ用的是上传控件吧
在上传的时候控件文件类型就OK
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/UploadedImages/");
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{".gif", ".png", ".jpeg", ".jpg"};
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
}
}

摘自MSDN
bill024 2007-01-10
  • 打赏
  • 举报
回复
ValidationExpression=@"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.rar|.RAR|.zip|.ZIP)$"

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧