[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Regex for file naming convention.

Posted on 2008-10-14
Medium Priority
Last Modified: 2012-05-05
Before allowing users to upload files in my application, I need to verify that the
file name follows a strict naming convention.  The first 17 characters must
be formatted as follows:

Ex.  87-2398(20041231).pdf

Please help me with regular expressions that will validate this file naming convention.

Question by:JeffDrummond
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 27

Expert Comment

ID: 22711294
In general:

If you want a more specific validation performed on the numbers in the pattern (dates etc.) you will need to do that in code.

Author Comment

ID: 22711315
Hi ddrudik:

Thanks for the quick response.  I've used your suggestions before to
great effect.

What if I want to leave off the .pdf part of the validation and
just have a regex for this part:  NN-NNNN(YYYYMMDD)  

LVL 27

Accepted Solution

ddrudik earned 2000 total points
ID: 22711438

Remove the $ if you are passing a string that contains something after the ) in the filename.

Author Comment

ID: 22713661
Thanks again.  Right on target.
LVL 27

Expert Comment

ID: 22713681
Thanks for the question and the points.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question