How To Use Regular Expression To Validate File Path (Folder Location) In JavaScript and JQuery?

Jquery_logo

Today we will learn, How To Use Regular Expression To Validate File Path (Folder Location).


Suppose you want to validate a folder location like: d:\bang pics\tom-check-6.0\inner  or D:\bang pics\tom-check-6.0\inner we can do it using  Regular Expression.Here is the expression :


/^([A-Za-z]:)(\\[A-Za-z_\-\s0-9\.]+)+$/;


Explanation:
1.  ([A-Za-z]:)     for d: or D: (drive name)
2.  (\\[A-Za-z_\-\s0-9\.]+)+     for \folder_name (recursive way)   + sign for recursion (e.g \my\music\etc).
Check running example here:
http://jsfiddle.net/jeetu_verma11/sRmhF/
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

1 comments:

  1. Good article. Unfortunately, it doesn't validate network paths like \\myStore\Home\Room

    ReplyDelete