How to display age as years, months and days?

leighh77457178

10-10-2018

Hi

I have a form created in livecycle designer and one of the fields is age at diagnosis - I want to format the field to allow the user to enter the age the person was at diagnosis manually (its not calculated from date of birth (DOB) or from any other date its just an age that the  person completing the form would know). If I want to manually add this to a field how can I format it so that the user enters the age in years months and days? Currently we are experiencing a few problems as some people are using the field to enter the age in months and then some are entering the age in years so its a bit confusing when trying to analyse this data.

I want to make it as easy as possible to enter the age in the format I want i.e. years months and days.

thanks in advance!

View Entire Topic

mouslander

10-10-2018

The simplest approach would be for there to be 3 fields with Y, M, D however if this isn't possible then you would need to first determine how you want it the user to enter the info. For example if you want them to enter 3 years, 7 months 45 Days what is the format you expect? Is it"

03, 07, 45 or 03-07-45 or even 03y, 07m, 45d?

Once you determine that, then you will need to use a regular expression to maintain the format. You will also need a warning if the format is not correct and remove the incorrect entry.

Below is a similar script I created for a formatted date field. You should be able to modify this for your format:

var myRegExp = /[0-1][0-9]\/[0-3][0-9]\/\d{4}/; // Created a regular expression for the date format

var myText = ExecFromDate.rawValue; //variable to store the field

if(ExecFromDate.rawValue == null){ //checking for empty field

ExecFromDate.rawValue = null;

}

else

if(myRegExp.test(myText)== false){ //validate input against regular expression

xfa.host.messageBox("You have entered an incorrect date format. Please use MM/DD/YYYY", "Date error", 3, 0); //warning if incorrect format

xfa.host.setFocus("ExecFromDate") //sets the user back to the date field

ExecFromDate.rawValue = ""  //clears the entry

}