I am currently using Ruby on Rails 3 and Prototype, and I need to be able to check the file extension when a file is selected with file_field
. I only want to allow files with extensions of .doc
or .pdf
, any other extensions should display an error.
In my view file, I currently have the file_field
set up like this:
page.event.observe('file_field_id', 'change') do |element|
# Need code here to check the file extension
# If it's not '.doc' or '.pdf', show an error in the 'error_id'
end
After selecting a file, I need to verify that the file has either a .doc
or .pdf
extension. If not, I want to set and display an error message in the error_id
.
How can I achieve this?
UPDATE: I specifically require the use of the Prototype framework. Is this possible?