from date and to date validation in angular 9

Solutions on MaxInterview for from date and to date validation in angular 9 by the best coders in the world

showing results for - "from date and to date validation in angular 9"
Federico
27 Feb 2017
1export class CustomeDateValidators {
2    static fromToDate(fromDateField: string, toDateField: string, errorName: string = 'fromToDate'): ValidatorFn {
3        return (formGroup: AbstractControl): { [key: string]: boolean } | null => {
4            const fromDate = formGroup.get(fromDateField).value;
5            const toDate = formGroup.get(toDateField).value;
6           // Ausing the fromDate and toDate are numbers. In not convert them first after null check
7            if ((fromDate !== null && toDate !== null) && fromDate > toDate) {
8                return {[errorName]: true};
9            }
10            return null;
11        };
12    }
13}
14
15/*--- implementations ---*/
16this.form = this.fb.group({
17  fromDate: null,
18  toDate: null,
19}, { validator: [
20  //Default error with this validator:  {fromToDate: true}
21  CustomeDateValidators.fromToDate('fromDate', 'toDate')
22  
23  // For custome error name like: {customeErrorName: true}, pass third optional parameter with custome name
24  // CustomeDateValidators.fromToDate('fromDate', 'toDate', 'customeErrorName')
25]});
26
Constanza
02 Jan 2017
1export class CustomeDateValidators {
2    static fromToDate(fromDateField: string, toDateField: string, errorName: string = 'fromToDate'): ValidatorFn {
3        return (formGroup: AbstractControl): { [key: string]: boolean } | null => {
4            const fromDate = formGroup.get(fromDateField).value;
5            const toDate = formGroup.get(toDateField).value;
6           // Ausing the fromDate and toDate are numbers. In not convert them first after null check
7            if ((fromDate !== null && toDate !== null) && fromDate > toDate) {
8                return {[errorName]: true};
9            }
10            return null;
11        };
12    }
13}
14
15/*--- implementations ---*/
16this.form = this.fb.group({
17  fromDate: null,
18  toDate: null,
19}, { validator: [
20  //Default error with this validator:  {fromToDate: true}
21  CustomeDateValidators.fromToDate('fromDate', 'toDate')
22  
23  // For custome error name like: {customeErrorName: true}, pass third optional parameter with custome name
24  // CustomeDateValidators.fromToDate('fromDate', 'toDate', 'customeErrorName')
25]});
26
27
queries leading to this page
angular date validatehow to to validate date in angular8date validation in angularjsdate validation in angular 6angular date validation pastvalidate date format angular 8angularjs date validationangular validation form datedate validation in angular 8 validhow to validate date in angular jsvalidate date in angular formangular from date to date validationdob date validation angular jsdatepicker start date end date validation angular 11from and to date validation in angulardate validator in form angularvalidator date angularvalidate date in angularangularjs datepicker startdate enddate validationangular validation function date fromstart date and end date validation in angular 4from date to date validation in angular 8angular start date end date validationhow to apply past date validations in angulardate pattern validation in angularvalidator for date angularend date start date validation angularhow to create custom date validator function in angularfuture date validation in angularangular from and to date validationangular validation datehow to validate date in angular jsangular date time picker validation examplehow to set a validation date in angular to set a date after anotherhow to set a validator date in angular to set a date after anotherhow to validate start and end date in angularstart date and end date validation in angular 8start date time and end date time validation in angulardate validation angularangular valid datehow to validate start date and end date in angularangular validate datedate validation in angular 8date validator in angularangular date validationfuture date validation in angular 6how to create custom date validator functions in angularfrom date to date validation angularvalidate date values angularvalidation for date in angulardate validations in angualrcheck date validation in javascript in all angular 9how to apply date validations in angularangular 8 form validations start date 3c 3d end datestart and end date angular validatortwo date validation in angular 8date validation in angular formto date validation in angular 7from date and to date validation in angular 8angular setvalidators start date end date custom messagedate validation in angularangular 8 start end date validationfrom date and to date validation in angular 9start date and end date validation in angular 6date validator angularangular validate a datecurrent date validation in angular 8from date and to date validation in angular 9