×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Looks ok to me you could also have gone for
"/^[\w | -]+\.\w+$/"
The only comment i have is that your only validation on the extension is
that it is at least 1 char. Depending on your needs you might want to set a
max for the extension.
"/^[[\w | -]+\.\w{1,4}$/" forces the extension to be at least 1 char and at
most 4 chars.
Neill
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of BMay@xxxxxxxxx
Sent: 16 July 2009 16:19
To: midrange-l@xxxxxxxxxxxx
Subject: Using a regular expression to validate a file name
I just need a quick sanity check. I am not as proficient with regular
expressions as I would like.
I have been using the following expression to validate file names uploaded
and retrieved from our root IFS file system
"/^\w+\.\w+$/"
This ensures that the file name and suffix contain only letters, numbers,
and underscores.
I had a new requirement to allow dashes in the file name. So I changed
the expression to this.
"/^[A-Za-z0-9_-]+\.\w+$/"
Any gotchas that I might be missing in this change?
Thanks,
Brian May
Project Lead
Management Information Systems
Garan, Incorporated
Starkville, Mississippi
Young i Professionals
http://www.youngiprofessionals.com
As an Amazon Associate we earn from qualifying purchases.