File validators in Angular

Whenever you allow users to upload files to your server, you should have both client side and server side validation. Most likely you will validate file size and file type, identifiable by the file extension. FileValidator covers all three aspects. Example of usage is below the source code. If you are using Angular, you can use these simple validators. If you do use them, or find them inspiring, please let me know. import { ValidatorFn, FormControl } from ‘@angular/forms’; export class FileValidator { static fileMaxSize(maxSize: number): ValidatorFn { const validatorFn = (file: File) => { if (file instanceof File && …

Continue Reading