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

  • Home
  • SEARCH
  • 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 7840799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:55:17+00:00 2026-06-02T15:55:17+00:00

I have a form and there I wanna allow to user upload only one

  • 0

I have a form and there I wanna allow to user upload only one type of file. I use client side validation, but the file-type validation has not behavior as I would expected. I tried to validation the file type with these two ways:

  validates :doc_type, :allow_blank => true, :format => {:with => /\A.*\.(pdf|PDF)\z/, :message => 'must be PDF file.'}

and also

validates_attachment_content_type :doc_type, :content_type => { :content_type => "application/pdf" }

But the error about bad file type is not displayed via Client side validation, but as usual validation error.

Exist any way to display the validation error by Client side validation?

  • 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-06-02T15:55:19+00:00Added an answer on June 2, 2026 at 3:55 pm

    I suggest using the jquery validate plugin on the client side first, before submitting to your back end. This allows you to validate file types on the front end.

    http://docs.jquery.com/Plugins/Validation/Methods/accept

    Here is a sample, makes “field” required and ending with “.xls” or “.csv”.

    $("#myform").validate({
      rules: {
        field: {
          required: true,
          accept: "xls|csv"
        }
      }
    });
    

    The great thing about using the jquery validation plugin is that it will also make other ciient side validations convenient, like email, password, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two form. at form 1 there are: 1. one group of radiobutton
I have aps.net web form there is html input text: <input type=text class=input runat=server
I have one form: FormPrincipal.cs In this form there is a public method called
I have one form on a page and within that form there will be
I have two tables user and treeview . From my registration form I wanna
I have a form where there are 6 items, each of which can be
Scenario I have a Windows Forms Application. Inside the main form there is a
I have a form loading inside my page and there is a button out
Is there an easy way to have the form helpers set the tabindex parameter
I have a form that has multiple fields, and for testing purposes is there

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.