[thelist] regex to validate filenames

Hassan Schroeder hassan.schroeder at gmail.com
Fri Dec 1 15:50:52 CST 2006

On 12/1/06, Sarah Adams <mr.sanders at geekjock.ca> wrote:

> Basically, I want to validate a filename, checking to make sure that it
> is a gif or jpg, and that it has no illegal characters in it. The files
> are stored on a Linux box, so I'm using that as my basis for filenaming
> restrictions. My understanding is that these characters should be
> avoided in filenames on Linux:

Is there a reason not to just restrict the names to alphanumeric and
the hyphen character, as below? Assuming PERL regex, where \w is
[a-zA-Z_0-9] --


It'd make it a lot clearer :-)

(Not allowing a name to start with a hypen is a good idea, though!)

Hassan Schroeder ------------------------ hassan.schroeder at gmail.com

More information about the thelist mailing list