1

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?

0

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

5 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.