如何验证文件名是否合法?

boulder 2005-06-03 12:37:00
如何验证文件名是否合法。
如果用正则表达式如何验证?
...全文
286 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
minghui000 2005-06-03
  • 打赏
  • 举报
回复
帮您顶一下
boulder 2005-06-03
  • 打赏
  • 举报
回复
具体就是如何验证文件名中不包含如下字符:
\
/
:
,
*
?
"
'
<
>
|
louzu1 2005-06-03
  • 打赏
  • 举报
回复
up

要有具体的要求,才好解决
jerry_yuan 2005-06-03
  • 打赏
  • 举报
回复
bool state=false;
string temp=@"\/:,*?"'<>|"
string fname=textbox1.text.trim();
for (int i=0;i<temp;i++)
{
if(fname.index(temp.substring(i,1))>=0)
{
state=true;
break;
}
}
if (state)
{
……显示文件名错误的信息
}
mathsword 2005-06-03
  • 打赏
  • 举报
回复
Search Results
Expression: \A([A-Za-z0-9'~`!@#$%&^_+=\(\){},\-\[\]\;])+?([ A-Za-z0-9'~`
!@#$%&^_+=\(\){},\-\[\];]|([.]))*?(?(3)(([ A-Za-z0-9'~`!@#$
%&^_+=\(\){},\-\[\]\;]*?)([A-Za-z0-9'~`!@#$%&^_+=\(\){},\-\[
\];])+\z)|(\z))

Description: Used to match windows filenames. Fails if there is leading or trailing spaces. Fails if the input contains /\:*?"<>| . Fails if the input begins or ends with '.'
Matches: [Test.txt], [T est.txt], [Rosco's.Test.txt] [ More Details]
Non-Matches: [\Folder\Test.txt], [T*est.txt], [Test.]

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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