Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How can I force users to enter specifc format?

Avatar

Level 1

I'm using Livecycle Designer ES2 provided with Acrobat X Pro. 

I have a form where the age field is calculated from the date of birth field.  The date of birth field (DOB) is a date/time field.  The age field (Age) is a numeric field.

Problem is: when user enters 01/01/01 shows age as 101.  When user enters 01/01/2001 age shows 1.  All patterns are set to mm/dd/yyyy.  Is there a way to prohibit the user from continuing to the next field until the proper format is entered?  I'm open to any ideas which will acheive the desrired outcome.  I'm new to livecycle and javascript.  I suspect an easy solution but I can't seem to find it when searching the forums or LD help menu.

I've attached the script for the Age field in case it helps.

 

Age::calculate - (JavaScript, client)

 

var ageInYears = 0;

    var birthDate = new Date();

    if ( DOB.rawValue != null )

        {

        // Get current date, and convert user-entered date to a Date object.

        var curDate = new Date();

        birthDate.setTime(Date.parse(DOB.editValue));

       

        // Set initial age, current year - birth year

        ageInYears = curDate.getFullYear() - birthDate.getFullYear();

       

        // If we haven't reached the birth month yet, not yet 1 year older...

        if ( curDate.getMonth() < birthDate.getMonth() )

            ageInYears--;

        // If this month is same as birth month but we haven't reached the

        // birth date yet, not yet 1 year older...

        if ( curDate.getMonth() == birthDate.getMonth() )

            if ( curDate.getDate() < birthDate.getDate() )

                ageInYears--;

       

        // Set age in result field.

        this.rawValue = ageInYears;

            }

1 Accepted Solution

Avatar

Correct answer by
Level 7

In the exit event of the date of birth box put (in formcalc):

if (Date2Num($.formattedValue, "MM/DD/YYYY") == 0) then

    $=""

endif

and then under Object>Value just make sure you put a message into the 'Validation Pattern Message' saying something like: 'Please enter the date in the format MM/DD/YYYY'.

View solution in original post

4 Replies

Avatar

Correct answer by
Level 7

In the exit event of the date of birth box put (in formcalc):

if (Date2Num($.formattedValue, "MM/DD/YYYY") == 0) then

    $=""

endif

and then under Object>Value just make sure you put a message into the 'Validation Pattern Message' saying something like: 'Please enter the date in the format MM/DD/YYYY'.

Avatar

Level 10

Hi,

I would not force the user tio enter date in a specific format, this is often frustrating.

Better is to allow multiple ways of entering a date, which then is formatted in the desired format.

This is easy with using display and edit patterns.

http://thelivecycle.blogspot.de/2011/10/date-patterns.html

Avatar

Level 5

Radzmar,

Thanks for the great advice at: http://thelivecycle.blogspot.de/2011/10/date-patterns.html

However I can't get this method to work. I would like the date to display as MM-DD-YYYY regardless of what the user enters. 2 problems show up. First I get this annoying dialog box

Dialogue Box.JPG

and then second the date box doesn't even display the date in the MM-DD-YYYY format I would like. For instance if I enter 10/15/1994 the dialogue box above appears but doesn't display 10-15-1994, it just displays it as 10/15/1994. There seems to be a difference between pressing enter or return on keyboard after typing the date, versus just clicking out of the date box. I can't get a sample date in the "Sample" line like you had. Any ideas?

Display Tab.JPG

Edit Tab.JPGValidation Tab.JPGData Tab.JPG

Avatar

Level 2

I have nearly the same issue. I just want a MONTH YEAR the user can enter or pick from a drop down. I can get this to work until I meet the all caps requirement then its validation errors....