My folder path like d:\dd\ddd
(n no. of folders). It should validate whether it is correct or not.
The folder path should not accept d:\\\\\dd\\\ddd.
The folder path can accepted spaces like 'Program Files.
Please help me how to validate folder path using regex or java script?
Asked
Active
Viewed 7,300 times
1

Vijay
- 71
- 2
- 12
1 Answers
1
How about
^[a-zA-Z]:\\(\w+\\)*\w*$
Then in JS, you could check if a string matches by
/^[a-zA-Z]:\\(\w+\\)*\w*$/.test(yourString)

Adracus
- 891
- 1
- 7
- 19
-
Hi, Thanks for quick reply. The folder d: is not constant. It can anything like c or d or e. – Vijay Feb 01 '16 at 14:53
-
Hi, It is working fine for the folder which is having no space between the folder name like 'ProgramFiles' but it is not working working for space between the folder name like 'Program Files' – Vijay Feb 02 '16 at 14:54
-
It is working fine for the folder which is having no space between the folder name like 'ProgramFiles' but it is not working working for space between the folder name like 'Program Files' – Vijay Feb 03 '16 at 05:32
-
Then the regex would be `^[a-zA-Z]:\\([a-zA-Z0-9.\-*.+]+([ ][a-zA-Z0-9.\-*.+]+)*\\)*([a-zA-Z0-9.\-*.+]+([ ][a-zA-Z0-9.\-*.+]+)*)*$` – Adracus Feb 03 '16 at 07:22
-
This is a bad regex. It would validate myPath//Is//////Flawed – Placeable Dec 13 '20 at 15:47