开发者

validate the path in javascript

How can I validate a folder path in javascript?

For example, if I enter the path:

 c:\myf开发者_开发知识库older\hi\

it must be validated to some expression saying user must input the path as:

c:\\myfolder\\hi\\

Users may specify a path of any length.


I would try the following regular expression:

if (user_given_string.match(/^[a-z]:(\\\\([a-z]+))*\\\\?$/i)) { OK } else { wrong }


if(path.match(/^[a-z]+\\/|\\){1,2}([^\/\\\<\>\:\"\?\|\*]+(\/|\\))*[^\/\\\<\>\:\"\?\|\*]+\.[a-z]+$/i)) 
{
   true;
}
else 
{
   false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜