C#中的文本框文本文件夹路径验证 [英] Textbox text folder path validation in C#
本文介绍了C#中的文本框文本文件夹路径验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI,
我在c#
中有一个文本框控件当用户输入文件夹路径时(D:/ files / TEMP / 2WN)如果没有文本框中的扩展名,如何验证按钮提交中的文本框路径。
< asp:TextBox ID =txtFolderNamerunat =serverMaxLength =50Width =416px>< / asp:TextBox>
< asp:RequiredFieldValidator ID =rfvFolderNamerunat =serverControlToValidate =txtFolderNameForeColor =RedDisplay =DynamicErrorMessage =文件夹名称不能为空>
asp:RegularExpressionValidator
ID =revFolderNamerunat =serverControlToValidate =txtFolderName
ErrorMessage =无效的文件夹路径ValidationExpression =^( ?:[\w] \:| \\)(\\ [A-z_\-\s0-9\。] +)>< / ASP:的RegularExpressionValidator>
请给我一个想法。
非常感谢
我尝试过:
ValidationExpression =^( ?:[\ w] \:| \\)(\\ [a-z_ \-\s0-9 \。] +)
a- zA-Z] :( \\\\ + +)* \\ [a-zA-Z0_9] +)
([a-zA-Z]:| \\\ \\\\ [\\\] *)(\\\\\ [\\\\。] * | \\%[\\\。] +%+) + |%[\\\ \\。] +%(\\\\\ [\\\\。] * | \\%[\\\\。] +%+)*)
解决方案
hi
你的正则表达式只是chec国王的开始不是字符串的结尾。
最后尝试添加
。
^(:[\w] \:|?\\)(\\ [A-z_\-\s0-9\] +)
它将在最后消除非法字符的可能性。
如果你想检查特定的文件格式,请添加以下格式
^(:[\w] \:|?\\)。(\\ [A-z_\-\s0-9\] +)+ \(TXT | GIF | PDF | DOC |的docx | XLS | XLSX)
HI, I have a textbox control in c# When a user enters folder path(D:/files/TEMP/2WN) without extension in a textbox, how to validate the textbox path in button submit. <asp:TextBox ID="txtFolderName" runat="server" MaxLength="50" Width="416px"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvFolderName" runat="server" ControlToValidate="txtFolderName" ForeColor="Red" Display="Dynamic" ErrorMessage="Folder Name cannot be empty"> asp:RegularExpressionValidator ID="revFolderName" runat="server" ControlToValidate="txtFolderName" ErrorMessage="Invalid Folder Path" ValidationExpression="^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)"></asp:RegularExpressionValidator>
Please give me idea.
Thanks inadvance
What I have tried:
ValidationExpression="^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)" a-zA-Z]:(\\w+)*\\[a-zA-Z0_9]+) ([a-zA-Z]:|\\\\\w[ \w\.]*)(\\\w[ \w\.]*|\\%[ \w\.]+%+)+|%[ \w\.]+%(\\\w[ \w\.]*|\\%[ \w\.]+%+)*)
解决方案
hi
your regular expression is only checking the start not the ending of the string.
try add
at the end.
^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)
it will remove chance of illegal characters at the end.
if you want to check for specific file formats add the formats as below
^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)
这篇关于C#中的文本框文本文件夹路径验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文