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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With