import { buildMessage , isPhoneNumber , ValidateBy } from 'class-validator' ; export function IsPhoneNumberOrEmpty ( region ? ) { return ValidateBy ( { name : 'isPhoneNumberOrEmpty' , constraints : [ region ] , validator : { validate : ( value , args ) => { return value === '' || isPhoneNumber ( value , args . constraints [ 0 ] ) ; } , defaultMessage : buildMessage ( eachPrefix => eachPrefix + '$property must be a valid phone number' ) } } ) ; }