Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex Directory Name Validation [closed]

Tags:

c#

regex

vb.net

I want to check if a textbox have a valid directory name. Because I will create a directory with this textbox value.

Another thing, the value must have at least 3 characters and cannot have more than 20 characters.

How can I do it?

like image 650
Muhammed Uğur Nazlı Avatar asked Sep 13 '26 20:09

Muhammed Uğur Nazlı


1 Answers

Path.GetInvalidPathChars is where you can find out which characters are invalid. Rather than use regex, I suggest you use Path.GetFullPath as this will validate the path for you: invariably it will do a better job than anything you will try to roll yourself and will be kept up-to-date as the rules change over time.

As for its length, use the methods of the Path class to get the component of the path that you want to check.

like image 61
Paul Ruane Avatar answered Sep 16 '26 08:09

Paul Ruane