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/
Good article. Unfortunately, it doesn't validate network paths like \\myStore\Home\Room
ReplyDelete