import { ValidationErrors, } from 'ngrx-forms'; import { MMYY_DATE_FORMAT_REGEX, } from './../../../models/index'; /** * Best used with mmyy-date-format-validation to ensure the date is in the * correct format. */ export const mmyyFutureDateValidation = ( value: string | null, ): ValidationErrors => { if (!value) { return null; } const [ month, year ] = value.split('/'); const monthNumber = parseInt(month, 10); const currentDate = new Date(); const date = new Date(2000 + parseInt(year, 10), monthNumber - 1); if (monthNumber > 12 || date <= currentDate) { return { mmyyFutureDateValidation: true, }; } return null; };