Click here to Skip to main content
15,506,209 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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\.]+%+)*)
Posted
Updated 22-May-18 18:58pm
Comments
sai.2012 22-May-18 17:04pm    
Forgot to Delete the old post , Now I deleted.

1 solution

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)$
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900