I have an age script running in the attachment below. It works fine for numbers such as 1 22 1980.
[CODE]if ((input.search(/b([1-9]|[12][0-9]|3[01])b/)!= -1) && (input.search(/b([1-9]|1[0-2])b/)!=-1) && (input.search(/b(19[0-9]{2}|200[0-9]|201[01])b/)!= -1)) {
function getBirth() {
var now = new Date();
var myMatchy = input.match(/b(19[0-9]{2}|200[0-9]|201[01])b/);
var myMatchm = input.match(/b([1-9]|1[0-2])b/)
var myMatchd = input.match(/b([1-9]|[12][0-9]|3[01])b/);
var year = myMatchy[0];
var month = myMatchm[0];
var day = myMatchd[0];
var today =
{
“year” : now.getFullYear(),
“month”: now.getMonth()+1,
“day” : now.getDate()
}
var age = today[“year”] – year;
if (month > today[“month”])
age–;
else if (month == today[“month”])
if (day > today[“day”]) age–
return age;
}
document.result.result.value = “Your age is “+getBirth()+”.”;
return true;}
However, if someone writes out the month it doesn’t. Such as January 22 1980. I did a work-around by inserting the month value. Highlighted below. But that means I would have to duplicate this lengthy code 12 times for each month of the year. Anybody know a better way to handle this? You can test it in the small attachment below. Any help would be appreciated.
[CODE]if ((input.search(/b([1-9]|[12][0-9]|3[01])b/)!= -1) && (input.search(/(january)/)!= -1) && (input.search(/b(19[0-9]{2}|200[0-9]|201[01])b/)!= -1)) {
function getJan() {
var now = new Date();
var myMatchy = input.match(/b(19[0-9]{2}|200[0-9]|201[01])b/);
var myMatchd = input.match(/b([1-9]|[12][0-9]|3[01])b/);
[COLOR=”Red”]var month = 0;[/COLOR]
var year = myMatchy[0];
var day = myMatchd[0];
var today =
{
“year” : now.getFullYear(),
“month”: now.getMonth()+1,
“day” : now.getDate()
}
var age = today[“year”] – year;
if (month > today[“month”])
age–;
else if (month == today[“month”])
if (day > today[“day”]) age–
return age;
}
document.result.result.value = “Your age is “+getJan()+”.”;
return true;}
[upl-file uuid=75660092-a659-4f5a-9d32-10cf228ed5fa size=3kB]aademo.txt