How can the file extension be validated in an input type file using JQuery?

后端 未结 4 1244
后悔当初
后悔当初 2021-01-22 02:35

HTML:


Rule: The file to

4条回答
  •  半阙折子戏
    2021-01-22 02:51

    You simply need to pull the value of the element:

    var fileName = $('#group_document_file').val();
    
    var extension = fileName.slice('.')[fileName.slice('.').length - 1].toLowerCase();
    
    if(extension == 'jpeg' || extension == 'gif' || extension == 'png')
       // Show Validated Image
    else
       alert('Choose a supported image format');
    

提交回复
热议问题