DATE VALIDATION dd/mm/yyyy (date field with manual entry) | Community
Skip to main content
September 12, 2007

DATE VALIDATION dd/mm/yyyy (date field with manual entry)

  • September 12, 2007
  • 23 replies
  • 96522 views
Is there a way to stop people filling in date fields manually?

since there is a calendar, there not only is no need for manual entry but it also avoids input error..



When I try to validate a date, it will either accept the manual date, or the calendar date but never both.



Does somebody have a solution for this? .. either to validate both the calendar date & manual entry (entered in dd/mm/yyyy)



Or

to prevent users from typing inside the date field (& use the calendar!)

(or prevent them from typing anything other than dd/mm/yyyy)



('ve tried regular expressions but it does not accept the value from the calendar)



Thanks hopefully!
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

23 replies

tarekahf
Level 8
February 20, 2009
Dear All,



Forget it ! You will never be able to achieve what you are looking for in Date Validation.



What you got is what you got, not more not less, and you have to learn to live with it.



I would like to report also another problem which I am facing since ever, and just today I was able to identify the cause.



If you go to Control Pane, Regional and Language Setting under Advanced tab, the selection of "Language for non-Unicode programs", if you choose a Language say "Arabic", and after you restart the PC, then the Date Field of LiveCycle Designer will not work properly.



What will happen in this case ?



After you select a Date from the Drop-Down selection, then the date format is preset always to "DD/MM/YYYY", and the date value of say "12-Feb-2009" will show like this "٢٠٠٩-٠٢-١٢" (Indian Digit Shape), and no matter what you do, you will always get the same format, and the Date Validation will always report error.



So this looks like a bug, and I hope that this bug will be reported to Adobe Support Team.



Tarek.
Level 8
February 23, 2009
Tarek,



Maybe you should report this bug because you have the problem and will know the details.



The date field not only uses the calendar, and a formatted date string, but it will also process a UTC date. So if you really want to strictly control this, you will need to write your own validation script.
December 20, 2013

One of the useful ways I found out to validate the date is using the small script below: 

Write this in the validate method: 

var d1 = util.scand("yyyy-mm-dd", this.rawValue);

if ( d1 == null ){

      this.rawValue = "";

}

Geckoz100
Level 5
June 2, 2015

I've gotten some great help from others who helped me put together this great script.  Put it in the Validate event of your date field.  Remember to disable all validation from the Object pallet Patterns button.  The script allows the user to type only numbers and populates the slashes automatically.  Change the order the the mmddyyyy masks throughout, as needed.  I've been using this in many forms, works like a charm.


//Custom Date Validation Java Script for entering dates using numbers only


//With assistance from Ricardo Falegnami and BR001



// adding slashes


var newDate = this.rawValue;


// validate date


if (newDate !== null)


  { // process non-empty string


    var oMyDate = [];


    oMyDate[0] = util.scand("mmddyyyy", newDate);


    oMyDate[1] = util.scand("mddyyyy", newDate);


    oMyDate[2] = util.scand("mmdyyyy", newDate);


    oMyDate[3] = util.scand("mdyyyy", newDate);


    oMyDate[4] = util.scand("mmddyy", newDate);


    oMyDate[5] = util.scand("mdyy", newDate);



    var isDate = false;



    for (var i=0; i < oMyDate.length; i++)


    {


        if (oMyDate[i] !== null) {


            this.rawValue = util.printd("mm/dd/yyyy", oMyDate[i]); // strict format


            isDate = true;


            break;


        }


    }



// Stay in field if invalid


    if (isDate === false) {


        app.alert("Invalid date entered -- please enter in MMDDYYYY format, \n\nfor example, 051920152)", 0, 1, "CHECK DATE FORMAT"); // check validity


        xfa.host.setFocus(this)();


    }


}


Geckoz100
Level 5
March 24, 2016

I managed to sort it out using this code:

     var fldDate = this.getField("DOB").value;

     var strDate = "12122004";

     fldDate = fldDate.toString();

     app.alert("Field Date is " + fldDate + " and the type is : " + typeof fldDate);

     app.alert("String Date is " + strDate + " and the type is : " + typeof strDate);

     var fmtDate = util.scand("ddmmyyyy", fldDate);

     app.alert("Print this is scand date: " +fmtDate);

     app.alert("THis is printd date: " + util.printd("dd/mm/yyyy", fmtDate));

It became apparent that the date (12122004) put into the field was stored as a type "num" and scand needed a string. Once I did the type conversion life was good.

If I was able to us this.rawvalue - the type conversion may not have been a issue?

I am now going to use regexp to limit my users to ddmmyyyy or ddmmyy.

Format like dmmyy are too easy to be interpreted either way.

Regards,

-Al


I thought perhaps the javascript syntax might be a little different in Acrobat vs. LiveCycle.  If it's not, that's good to know.  But after working in LCD, I never do anything in Acrobat any more.

That type conversion was a smart move; I don't think I could have figured that out.  I'm not a very experienced coder.  But I don't understand why you were getting nothing from the rawValue; did you ever figure that out?  BTW, where is OZ?