import { FieldValidation } from '@/validation/protocols' ; import { InvalidFieldError } from '@/validation/errors' ; export class EmailValidation implements FieldValidation { constructor ( readonly field ) { } validate ( input ) { const emailRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ ; return ( ! input [ this . field ] || emailRegex . test ( input [ this . field ] ) ) ? null : new InvalidFieldError ( ) ; } }