Hi guys,
I need directory validation code... means when you make a directory through code and check wheather the directory name is valid or not...
so guys can nebuddy help me how to write the code for validating directory name.
Validating the name itself?
What characters do you allow for the directory name? Do you mean path, or only the name?
Yes... validating the directory name itself.
like such characters:- !@#$%&()+|\?/[]{}:;',.<>`~
I want only alphanumeric characters. which is the valid name for directory..
Then use setlocate(LC_CTYPE, "C"); if (ctype_alnum($dirname)) //alphanumeric else //too bad
You will probably want the underscore character too, and maybe a few other, so:
if (preg_match("/^[a-zA-Z0-9_]+$/", $dirname) == 1) //ok else //invalid
thnx you very much 🙂
what if I allow the space, - and _ characters in the directory name.. wat will be the regular expressions for that.
Probably something like:
if (preg_match("/^[a-zA-Z0-9_\- ]+$/", $dirname) == 1) //ok else //invalid
Originally posted by laserlight Probably something like: if (preg_match("/^[a-zA-Z0-9_\- ]+$/", $dirname) == 1) //ok else //invalid [/B]
Originally posted by laserlight Probably something like:
[/B]
I have tried this but it gimme such error
Warning: Compilation failed: range out of order in character class at offset 13 at line if (preg_match("/[a-zA-Z0-9_- ]+$/", $dirname) == 1)
its working now. I have done a minor change in sequence of regular expression.
if (preg_match("/^[a-zA-Z0-9_- ]+$/", $txtFolder) == 1)
instead i have used
if (preg_match("/^[a-zA-Z0-9 _-]+$/", $txtFolder) == 1)
thanks buddy 🙂