• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Regex for file naming convention.

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:

1.  NN-NNNN(YYYYMMDD).pdf
Ex.  87-2398(20041231).pdf

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

Thanks!
0
JeffDrummond
Asked:
JeffDrummond
  • 3
  • 2
1 Solution
 
ddrudikCommented:
In general:
^\d\d-\d{4}\(\d{8}\)\.pdf$

If you want a more specific validation performed on the numbers in the pattern (dates etc.) you will need to do that in code.
0
 
JeffDrummondAuthor Commented:
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)  

Thanks.
0
 
ddrudikCommented:
^\d\d-\d{4}\(\d{8}\)$

Remove the $ if you are passing a string that contains something after the ) in the filename.
0
 
JeffDrummondAuthor Commented:
Thanks again.  Right on target.
0
 
ddrudikCommented:
Thanks for the question and the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now