String path validation
- by CMAñora
I have here a string(an input from the user) for a file path. I checked the string so that it will qualify the criteria:
check for invalid characters for a file path
will not accept absolute path (\Sample\text.txt)
I have tried catching the invalid characters in catch clause. It work except for '\'. It will accept 'C:\\Sample\text.txt' which is an invalid file path.
The following examples should be invalid paths:
:\text.txt
:text.txt
\:text.txt
\text.txt
C:\\\text.txt
I have been through similar questions posted here but none of them seemed to solve my issue.
What would be the best way to do such check?