Check client side validation for file extension

http://blog.navayan.com/jquery-validation-for-file-type-extension/#.Uzq7Mt3AOkc

<scripttype="text/javascript">
  $(function(){
    $('input#submit').click(function(){var file = $('input[type="file"]').val();var exts =['doc','docx','rtf','odt'];// first check if file field has any valueif( file ){// split file name at dotvar get_ext = file.split('.');// reverse name to check extension
        get_ext = get_ext.reverse();// check file type is valid as given in 'exts' arrayif( $.inArray ( get_ext[0].toLowerCase(), exts )>-1){
          alert('Allowed extension!');}else{
          alert('Invalid file!');}}});});</script>
Advertisements