Get selected file extension using jquery

This example shows you how to check the file extension from file upload control selected value or from a given file name.


Example:


Code:
function CheckFileExtension() { var ext = $("#fupSample").val().split('.').pop(); alert(ext); };

Source Code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script language="javascript"> function CheckFileExtension() { var ext = $("#fupSample").val().split('.').pop(); alert(ext); }; </script> </head> <body> <div> <input type="file" id="fupSample" style="width: 200px;" />   <input type="button" value="Check Extension" onclick="CheckFileExtension();" /> </div> </body> </html>