Script:
function PopulateDateofBirthAndAge(NRICValue) {
var var1 = value.substring(0, 2);
var var2 = value.substring(2, 4);
var var3 = value.substring(4, 6);
var d = new Date();
d.setDate(var3);
d.setMonth(var2);
d.setYear(var1);
NRIC_TextInput(value, var1, var2, var3);
}
function NRIC_TextInput(id, yearid, monthid, dayid) {
var value = id;
if (value && value.length == 12) {
var isValid = true;
var n = value.split("");
var Year = parseFloat("20" + n[0] + n[1]);
var Month = parseFloat(n[2] + n[3]);
var Day = parseFloat(n[4] + n[5]);
var Now = new Date();
var Age = 0;
var sMonth = "";
if (Month < 1 || Month > 12) isValid = false;
if (isValid) {
if (Year > Now.getFullYear()) {
Year = Year - 100;
//Age check on month and date reach ?
Age = Now.getFullYear() - Year;
}
else {
//Age check on month and date reach ?
Age = Now.getFullYear() - Year;
}
switch (Month) {
case 1:
sMonth = "January";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 2:
sMonth = "February";
if (Year % 4 == 0) {
if (Day > 29 || Day <= 0) isValid = false;
} else {
if (Day > 28 || Day <= 0) isValid = false;
}
break;
case 3:
sMonth = "March";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 4:
sMonth = "April";
if (Day > 30 || Day <= 0) isValid = false;
break;
case 5:
sMonth = "May";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 6:
sMonth = "June";
if (Day > 30 || Day <= 0) isValid = false;
break;
case 7:
sMonth = "July";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 8:
sMonth = "August";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 9:
sMonth = "September";
if (Day > 30 || Day <= 0) isValid = false;
break;
case 10:
sMonth = "October";
if (Day > 31 || Day <= 0) isValid = false;
break;
case 11:
sMonth = "November";
if (Day > 30 || Day <= 0) isValid = false;
break;
case 12:
sMonth = "December";
if (Day > 31 || Day <= 0) isValid = false;
break;
default:
isValid = false;
break;
}
}
if (isValid) {
Xrm.Page.getAttribute("vwlzs_age").setValue(Age);
var DOB = new Date(Year, monthid - 1, dayid, 0, 0, 0);
Xrm.Page.getAttribute("vwlzs_dateofbirth").setValue(DOB);
} else {
alert("Invalid NRIC Number.");
}
}
else {
alert("Invalid NRIC Number.");
}
}
CRM 2013 Javascript Populate Date of Birth and Age from NRIC/MyKad
Posted by Unknown at 1/13/2015 02:47:00 pm
Labels: CRM 2013, Javascript
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment