• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • 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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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