I need to validate a user text entry for a directory based on Windows, there is no directory picker of sort, it is just a text field.
I have written the following Regex using http://regex101.com/ which works adequately for my needs:
^[a-zA-Z]\:[\/,\\].{1,}
Which will match for example the following directories in the online tool:
C:/Users/Charlie/Dropbox
D:/Users/Bob/Quotes
F:/Quotes
The problem is, when using it in my application, preg_match
does not match any of the above. It does not return true, and the preg_last_error()
returns 0
which also indicates a false return value.
The exact code used is:
if(preg_match('/^[a-zA-Z]\:[\/,\\].{1,}/', $directory)) { }
Any help much appreciated.