Hi,
I need Regular Expression for validate file path, In My case regex will accept both "/" and "\" ,
I tried all possibilities , but no one is working. it accepts URL also, So please Help Me to do this Validation
Thanks & Regards!!!!
-=Arun Prasath=-
Loading

Suthish NairRank #92 · 22.8K reputationPosted Jul 2, 2012, 9:18 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 2, 2012, 7:57 PM EDT
if you only validate file Path then try..
var f = Regex.IsMatch("D:\\JigneshTest\\", @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))$");
or URL validation
^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$
hope this will help you.
arun prasath94 reputationPosted Jul 2, 2012, 9:16 PM EDT
User Need to enter file path....after that we want validate is this valid file path or not...
Pls Help me Friends...
Thanks & Regards!
-=Arun=-
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 2, 2012, 9:23 PM EDT
For achieve both together combine both.
var f = Regex.IsMatch("D:\\JigneshTest\\", @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$");
hope this will help you.
arun prasath94 reputationPosted Jul 2, 2012, 10:35 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 2, 2012, 10:59 PM EDT
In Above post, I already combine Box Regex.
it work for both url as well as file path.
var f = Regex.IsMatch("D:\\JigneshTest\\", @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$");
Let me know if you have any query on same.
arun prasath94 reputationPosted Jul 3, 2012, 1:09 AM EDT