如何验证文件名是否合法?
如何验证文件名是否合法。
如果用正则表达式如何验证?
问题点数:20、回复次数:5Top
1 楼louzu1(伏龙芝)回复于 2005-06-03 12:51:29 得分 2
up
要有具体的要求,才好解决Top
2 楼boulder(day day up!)回复于 2005-06-03 12:57:06 得分 0
具体就是如何验证文件名中不包含如下字符:
\
/
:
,
*
?
"
'
<
>
|Top
3 楼minghui000(沉迷网络游戏)回复于 2005-06-03 12:58:29 得分 0
帮您顶一下Top
4 楼mathsword(梦在流浪)回复于 2005-06-03 13:02:46 得分 10
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.]
Top
5 楼jerry_yuan(jerry)回复于 2005-06-03 13:09:09 得分 8
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)
{
……显示文件名错误的信息
}Top




