How can a widget filter and validate files that user selects?

If you want to filter the certain type of files you would want to implement data-input-accept-types option. However, this option doesn’t completely restrict uploading other types of files. A user still can change the filter in the system dialog and select any type of file, so it is also important to reject submissions that contain files other than the ones you explicitly permit. File validators will do exactly that.

Let’s say you want your user to be able to submit only following file types: jpg, jpeg, gif, png, docx, xlsx, csv, rtf, pdf, mp4, mp3, ppt, pptx. This live demo shows how to set a validation function to achieve this.