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:

 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">

 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:



([a-zA-Z]:|\\\\\w[ \w\.]*)(\\\w[ \w\.]*|\\%[ \w\.]+%+)+|%[ \w\.]+%(\\\w[ \w\.]*|\\%[ \w\.]+%+)*)
Updated 22-May-18 18:58pm
sai.2012 22-May-18 17:04pm    
Forgot to Delete the old post , Now I deleted.

1 solution

your regular expression is only checking the start not the ending of the string.

try add $ at the end.


it will remove chance of illegal characters at the end.

if you want to check for specific file formats add the formats as below

Share this answer

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