The easiest way to check if a path is an UNC path is of course to check if the first character in the full path is a letter or backslash. Is this a good solution or could th
Maybe this answer can be helpful to someone who wants to validate only UNC server + share + subdirectories, for example path to network repository like
\\Server1\Share1\\Server2\Share22\Dir1\Dir2\\Server3Use the following regex:
^\\\\([A-Za-z0-9_\-]{1,32}[/\\]){0,10}[A-Za-z0-9_\-]{1,32}$
32 (2 times) with maximum allowed length of server/directory name10 with maximum allowed path depth (maximum count of directories)[A-Za-z0-9_\-] (2 times) if you are missing some character allowed in server/directory nameI've successfully tested it. Enjoy!