DATE VALIDATION dd/mm/yyyy (date field with manual entry) | Community
Skip to main content
Sep 12, 2007 6:20 AM UTC

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

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.

33 replies

Dec 20, 2013 9:18 AM UTC

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 = "";

}

Translate
Geckoz100
Level 5
Jun 2, 2015 5:01 PM UTC

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)();


    }


}


Translate
Level 2
Mar 23, 2016 3:17 PM UTC

Geckoz100‌ I really like what your code does, or should do but I cant get it to work.

If paste the code into a custom validation script or even a on blue event for a date field nothing happens.

I watched the value of newDate = this.rawValue but it is always undefined?

What am I missing?

Cheers

-Al

Translate
Level 8
Feb 23, 2009 2:16 PM UTC
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.
Translate
tarekahf
Level 8
Feb 20, 2009 11:35 PM UTC
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.
Translate
New Participant
Feb 19, 2009 7:59 PM UTC
We've done that (MM/DD/YYYY). However we're still getting that we can type in letters in the date and time field and we don't want that. We specifically want only the date. So can you walk me through what I need to do?
Translate
Nov 26, 2009 2:28 PM UTC

Hi - did you ever get an answer for this - to prevent users from entering text into a date field and using ONLY the calendar?
Regards,

B.

Translate
Level 3
Aug 14, 2013 3:58 PM UTC

Can you cut out all entry ability except calendar? I have hundreds of people entering the days in many ways which is messing up the field.

Translate
Level 8
Feb 19, 2009 7:39 PM UTC
Yes, but you need to set a lot of the optional formatting options for the field using the strings I posted above.



The format fields are CASE dependent!



The order of the date elements is important.
Translate
New Participant
Feb 19, 2009 5:35 PM UTC
Ok is there any way that you can get the DATE FIELD to only accept putting in the date or have the calendar in there, and not have any TEXT or LETTERS in there. I mean is there something I need to click on in Live Cycle to make this happen to where when you click on the date field you automatically get a calendar and can choose a date and cannot have an option to type any letters in? Anyone, please help.
Translate
Level 8
Feb 10, 2009 6:38 PM UTC
If you check the Adobe documentation pages for LiveCycle Designer there are many documents about creating forms in LiveCycle Designer.



"E" one digit day or week

"EEE" abbreviated day of week

"EEEE" full weekday name

"D" date without leading zero

"DD" 2 digit date with leading zero

"DDD" short day of week text string

"DDDD" long day of week text string

"M" month with leading zero

"MM" 2 digit month with leading zero

"MMM" Short month text string

"MMMM" long month text string

"YY" year as decade

"YYYY" full year



As with JavaScirpt and FromCalc case is important.



More information about date formats is contained in the "Scripting Reference" under LiveCycle Designer's menu bar "Help" option.
Translate
Feb 10, 2009 6:10 PM UTC
Not an exact solution. Needs a little work to prevent text characters:

~ works for dd/mm/yyyy; if not that format set field to null.



var DD = parseFloat(this.formattedValue.substr(0,2));



var MM = parseFloat(this.formattedValue.substr(3,2));



var YYYY = parseFloat(this.formattedValue.substr(6,2));



if(DD > 31 || DD < 1)



{



this.rawValue = null;

}



if (MM > 12 || < 1)



{



this.rawValue = null;



}



// if string length not 10 cant be correct



if (this.formattedValue.length != 10)



{

this.rawValue = null;



//look for first /



if( this.formattedValue.substr(2,1) != "/")



{



this.rawValue = null;



}



//look for second /



if( this.formattedValue.substr(5,1) != "/")



{



this.rawValue = null;



}



}
Translate
tarekahf
Level 8
Oct 22, 2008 10:20 PM UTC
By chance, and not sure exactly what solved the problem of working with Date Fields, I think when I made a small MS Access Table with Date Fields, and exported it to XML with Schema info, and created a connection to this XML/Schema from Adobe LiveCycle Form, then the Data Fields worked properly, but honestly, not sure exactly.



However, in my previous project, I used the functions in FormCalc to convert String input to Date Variable, and do the Validation. You could do that in JavaScript, but it is a bit more difficult.



Tarek.
Translate
Oct 22, 2008 9:58 PM UTC
I have the same problem. What java script did you use to check the data
Translate