So I have following piece of code which basically validates five date fields in angular service.But the catch is that there may be one to five field(s) visible on the screen based on some other criteria.So the code checks if one datepicker is shown it will only validate one input.If three datepickers are shown it would validate three inputs.this.isDatesValid = function (tarifForm) {     var valid = true;            //check Sinistres en 5 ans is 1/2/3/4/5 then based on that check the datepickers should not be empty     switch (Number(tarifForm.Attestation.sinistres)) {            case 1:                    if (tarifForm.Attestation.premiersinsiterdatepr1st.output == null) {                        valid = false;                        tarifForm.Attestation.firstSinisterDateinValid = true;                    }                    break;            case 2:                    if (tarifForm.Attestation.premiersinsiterdatepr1st.output == null) {                        valid = false;                        tarifForm.Attestation.firstSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr2nd.output == null) {                        valid = false;                        tarifForm.Attestation.secondSinisterDateinValid = true;                    }                    break;            case 3:                    if (tarifForm.Attestation.premiersinsiterdatepr1st.output == null) {                        valid = false;                        tarifForm.Attestation.firstSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr2nd.output == null) {                        valid = false;                        tarifForm.Attestation.secondSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr3rd.output == null) {                        valid = false;                        tarifForm.Attestation.thirdSinisterDateinValid = true;                    }                    break;            case 4:                    if (tarifForm.Attestation.premiersinsiterdatepr1st.output == null) {                        valid = false;                        tarifForm.Attestation.firstSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr2nd.output == null) {                        valid = false;                        tarifForm.Attestation.secondSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr3rd.output == null) {                        valid = false;                        tarifForm.Attestation.thirdSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr4th.output == null) {                        valid = false;                        tarifForm.Attestation.fourthSinisterDateinValid = true;                    }                    break;             case 5:                    if (tarifForm.Attestation.premiersinsiterdatepr1st.output == null) {                        valid = false;                        tarifForm.Attestation.firstSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr2nd.output == null) {                        valid = false;                        tarifForm.Attestation.secondSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr3rd.output == null) {                        valid = false;                        tarifForm.Attestation.thirdSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr4th.output == null) {                        valid = false;                        tarifForm.Attestation.fourthSinisterDateinValid = true;                    }                    if (tarifForm.Attestation.premiersinsiterdatepr5th.output == null) {                        valid = false;                        tarifForm.Attestation.fifthSinisterDateinValid = true;                    }                    break;            }            var inputdata = { sinistreEn5AnsAT: tarifForm.Attestation.sinistres, DateFifthSinister: commonUtilities.currentDateinDDMMYYYY(tarifForm.Attestation.premiersinsiterdatepr5th.output), DateFourthSinister: commonUtilities.currentDateinDDMMYYYY(tarifForm.Attestation.premiersinsiterdatepr4th.output), DateThirdSinister: commonUtilities.currentDateinDDMMYYYY(tarifForm.Attestation.premiersinsiterdatepr3rd.output), DateSecondSinister: commonUtilities.currentDateinDDMMYYYY(tarifForm.Attestation.premiersinsiterdatepr2nd.output), DateFirstSinister: commonUtilities.currentDateinDDMMYYYY(tarifForm.Attestation.premiersinsiterdatepr1st.output) };            this.isValidDate(inputdata, function (response) {                valid = Boolean(response.data);            });            return valid;        }In view validations are applied like this.I have only shown one case here. <div class=row>      <div class=push-four field eight columns>      <span class=msg-err ng-show=tarifForm.Attestation.secondSinisterDateinValid translate code=TarifficationErrorMsg$ErrorMsgRequiredCatalougeandInsured></span>      </div> </div>My question is can I simplify the above if conditions written.My objective is to reduce the number of redundant code in different if blocks.
Validating five date fields in Angular.js
javascript;datetime;validation;angular.js