-5

I need to validate folder path with having forward(/)slash

regex or javascript code should validate and allow below format path only.

ex1: "D:/dir1/dir2/dir3"

ex2: "c:/dirname1/somedir/dirname/batch.log"

ex3: "E:/user/desktop/somedir/fname.csv"

1

2 Answers 2

0
regx: '/^(?:[\w]\:|\/)(\/[A-z_\-\s0-9\.]+)+/g'

With version: '^(?:[\w]\:|\/)(\/[A-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx)$'

Expalnation :^(?:[\w]:|/) -- Begin with x:/ or //

[A-z_-\s0-9.] -- valid characters are a-z| 0-9|-|.|_ (you can add more)

(txt|gif|pdf|doc|docx|xls|xlsx) -- Valid extension (you can add more)

Sign up to request clarification or add additional context in comments.

1 Comment

frustrateddeveloper, Above solution is working fine. but now I need colon( : ) optional. for ex "c:/dirname1/somedir/dirname/batch.log", or "c/dirname1/somedir/dirname/batch.log" could you please help me here to achieve this.
-1

I think this will works:

 var pattern = "[(c|C|D|d|E|e)]:.*";
 var str = "E:/dir1/dir2/dir3";
 var result = str.match(pattern);

2 Comments

No Gnana paths can be.. D:/Inventory/Verizon/CVGRPT, D:/Inventory/Verizon/batch_reports/missing-report.csv
@shashikeshari I updated my answer please check now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.