Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  17] [ 4]  / answers: 1 / hits: 60801  / 14 Years ago, fri, november 12, 2010, 12:00:00

i want to check the type of uploaded file. If name like example.txt, i want to get the .txt part only. How can i achieve it using Jquery or javascript.



Any Suggestions or links would be appreciative!!!


More From » jquery

 Answers
4

A simple solution is .split() and .pop() to get the last string in the array, like this:



var ext = fileName.split('.').pop();


This will get you just txt without the ., just append if needed. This also works on say: My.File.name.has.an extension.txt as well. If it doesn't have an extension it'll return the file name, so you may want to check for this...or go a completely different direction and validate against a set or known extensions via regex.


[#94989] Wednesday, November 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sidneyh

Total Points: 118
Total Questions: 108
Total Answers: 105

Location: Mali
Member since Fri, Jun 18, 2021
3 Years ago
sidneyh questions
Tue, Jun 7, 22, 00:00, 2 Years ago
Wed, Apr 13, 22, 00:00, 2 Years ago
Wed, Aug 12, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Fri, Apr 24, 20, 00:00, 4 Years ago
;