Input type File validation – Client side

Thinking of allowing only specific file types to be browsed through File Input HTML field??

Here’ a simple regex based javascript that can help you out with the solution. It’s based on the file extension of file being browsed and clears the input field if validation fails. The allowed list of file extensions is exhaustive and can be changed as per the requirement. Since, its a client side validation, you need to complement it with server side validation as a practice.

Note: You need to include jQuery (mentioned below) to your page for leveraging this code in HEAD section of HTML.

Enjoy!!

  • vikky

    thanks alot of for this