Hi sir/madam,
I attempted to keep a validation on Date of Birth,i need a condition where if we select date of birth below 18 then it should show a validation like invalid date of birth ,
I tried this way but still i am not getting output .please check the code and help me in this situation.
hoping for positive reply.
methods: {
setValidationConfig: function() {
// Calls the initialization of validators for the parent view model.
this.callParent(arguments);
this.addColumnValidator("UsrDateOfBirth", this.DateOfBirthValidation);
},
DateOfBirthValidation: function(value) {
var invalidMessage = "";
var isValid = true;
var number = value || this.get("UsrDateOfBirth");
var nd = number.substr(0, 2);
var nm = number.substr(3, 2);
var ny = number.substr(6, 2);
var cnumber = "";
cnumber = nm + "-" + nd + "-" + ny;
var today = new Date();
var birthDate = new Date(cnumber);
//day
var tdate = today.toString();
var td = tdate.substr(8, 2);
td = parseInt(td, td);
var bd = number.substr(0, 2);
bd = parseInt(bd, bd);
var d = bd - td;
//year
var age = today.getFullYear() - birthDate.getFullYear();
//month
var todayMonth = today.getMonth() + 1;
var getMonthName = birthDate.toString();
var monthName = getMonthName.substr(4, 3);
var bdmonthnumber;
todayMonth = parseInt(todayMonth, todayMonth);
if (monthName === "Jan") {
bdmonthnumber = 1;
} else if (monthName === "Feb") {
bdmonthnumber = 2;
} else if (monthName === "Mar") {
bdmonthnumber = 3;
} else if (monthName === "Apr") {
bdmonthnumber = 4;
} else if (monthName === "May") {
bdmonthnumber = 5;
} else if (monthName === "Jun") {
bdmonthnumber = 6;
} else if (monthName === "Jul") {
bdmonthnumber = 7;
} else if (monthName === "Aug") {
bdmonthnumber = 8;
} else if (monthName === "Sep") {
bdmonthnumber = 9;
} else if (monthName === "Oct") {
bdmonthnumber = 10;
} else if (monthName === "Nov") {
bdmonthnumber = 11;
} else if (monthName === "Dec") {
bdmonthnumber = 12;
}
var m = todayMonth - bdmonthnumber;
//console.log("m"+m);
if ((age === 18) && (m === 0) && (d === 0)) {
isValid = true;
} else if ((age === 18) && (m === 0) && (d < 0)) {
isValid = false;
} else if ((age === 18) && (m === 0) && (d > 0)) {
isValid = true;
} else if (age < 18) {
isValid = false;
} else if (age > 18) {
isValid = true;
}
if (!isValid) {
invalidMessage = this.get("Resources.Strings.InvalidDOBFormat");
}
// Object which properties contain validation error messages.
// If the validation is successful, empty strings are returned to the object.
return {
invalidMessage: invalidMessage
};
},
Like
Hello again.
You are trying to achieve the task that is described in the article below:
https://academy.bpmonline.com/documents/technic-sdk/7-13/how-add-field-…
However, instead of the comparison of the due date with the closed on date you need to validate that the user is over 18 years of age. To do that you can use the samples from the below article:
https://stackoverflow.com/questions/4060004/calculate-age-given-the-bir…
Best regards,
Matt