Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:47:04+00:00 2026-05-22T22:47:04+00:00

I am trying to limit the user from uploading Long named files and unaccepted

  • 0

I am trying to limit the user from uploading Long named files and unaccepted file extensions using a regular expression validator in Asp.net 2.0 Webforms. I wanted the filename to be withing 30 characters[restriction due to Db Design] and extensions match png,jpeg,zip,rar,7z.I came up with this regular expression which makes sure filename is valid character and then comes . literal period then the extension.

^[\w_]{3,28}\.(pdf|jpeg|png)$

Update:
i came up with this regex that matches even last instance only that even long filenames get validated

(\\(?!.*\\)|)[\w_]{3,30}\.(pdf|jpeg|jpg|pdf)$

Update: Even this works just that fileName does not get limited to 30 characters

[\w]{3,30}\.(pdf|jpeg|jpg|pdf)(?=)

info: It even validated c:\fakePath\stackoverflowstackoverflowstackoverflowstackoverflow btw it highlighted last 30 characters in fileName.

The problem was that i want the validation to be done on client at time of uploading hence EnableClientScript = True , but to my surprise the fileUpload.value which the control validates was totally different in most of the browsers.

Firefox reports: filename.extension as expected,

Internet Explorer reported the Full Path to File

chrome reports C:\fakePath\fileName.extension

Now how do i write a expression for this, my idea was to look for last instance of the \ character if present in the value then begin form there. But my knowledge of Regex is totally limited to the basics. could someone correct me and provide a working regex,

Note:
Pls , before providing one make sure it met my requirements, works cross browser and validates on clientSide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:47:05+00:00Added an answer on May 22, 2026 at 10:47 pm

    I suggest this:

    \b\w{3,30}\.(?:pdf|jpe?g|png|7z|zip|rar)$
    

    This matches a filename starting at a word boundary (without the \b it might start the match in the middle of an overlong filename). Only ASCII letters, digits and underscores are allowed in the filename (no accented characters!), dots are also forbidden.

    Remember to construct the regex using regex literal notation:

    var myregexp = /\b\w{3,30}\.(?:pdf|jpe?g|png|7z|zip|rar)$/;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to limit the number of connections my server will accept using semaphores,
I'm trying to limit the number of records from an XML feed that are
I have an Oracle database where I'm trying to select a user field from
I'm trying to limit the amount of characters that a user can input. I
I'm trying this simple query: SELECT * FROM `Users` WHERE MATCH (`User`) AGAINST ('User')
I'm trying to implement a time limit a user has to answer a question
I'm having problems in uploading a file using Rails and jQuery, I'm using attachment_fu
I am trying to limit what a user can see to only his/her own
I'm currently trying to limit the memory resources of the process. Before to do
I am trying to limit connections and requests per IP then add a whitelist

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.