file extension validation in jQuery

Hello Friends,

Recently one of my project require file extension validation. I am using jquery to achive this. So, i have done it in simple way with jquery as follow

$(function ()
{
   $('#btnSubmit').click(function ()
   {
      var ext = ['jpeg', 'jpg', 'png', 'gif'];
      var file = $("file").val();
      if ($.inArray(file.split('.').pop().toLowerCase(), ext) == -1)
      {
          alert ('Only jpg, png and gif are allowed.');
      }
   }
}

Include HTML as follow.



It is work with jQuery js. So, include jQuery js file. Hope it will help someone!!!!