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?
1 Answer
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)
5 Comments
Vijay
Hi, Thanks for quick reply. The folder d: is not constant. It can anything like c or d or e.
Vijay
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
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'
Adracus
Then the regex would be
^[a-zA-Z]:\\([a-zA-Z0-9.\-*.+]+([ ][a-zA-Z0-9.\-*.+]+)*\\)*([a-zA-Z0-9.\-*.+]+([ ][a-zA-Z0-9.\-*.+]+)*)*$Placeable
This is a bad regex. It would validate myPath//Is//////Flawed