These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Date field with no "/" input

smithba
Registered: Aug 3 2007
Posts: 8

I want a date field in the mm/dd/yy format, but I don't want my users to input the "/". Can this be done?

My Product Information:
Acrobat Pro 8.0999999999999996447286321199499070644378662109375, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi smithba,

Sure, you can do this with JavaScript. Read this article at JavaScript Corner (link below) and downwload the example file. There is a Social Security number example that automatically inserts hyphens as the numbers are entered. You can inspect the script by selecting the field, Right Click, choose Properties, and look under the Format tab in the Custom Keystroke Script box. Of course, you will need a different script for the date and / instead of hyphens, but this shows you how symbols are auto-inserted between numbers during entry.

[url=http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/formatting_text_fields/]http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/formatting_text_fields/[/url]

Hope this helps,

Dimitri
WindJack Solutions
[url=http://www.windjack.com]www.windjack.com[/url]
smithba
Registered: Aug 3 2007
Posts: 8
Thanks Dimitri,
I found those examples and attempted to use the SSN script that you mentioned before I posted my first question.

If I copy and paste the script as it is, it works perfectly. As I begin to alter the code, it stops working. Also, I can't figure out how to replace the "-" with "/".

Can you give me some pointers for altering that code so that it will do what I need?
smithba
Registered: Aug 3 2007
Posts: 8
Problem solved..... Thanks for your help!

Here is the code in case there are others who need it......

if(!event.willCommit)
{
if(/^\d{2}$/.test(event.value) && event.selStart == 2)
event.change = "/" + event.change;
else if(/^\d{2}\/\d{2}$/.test(event.value) && event.selStart == 5)
event.change = "/" + event.change;

// Merge entered data
var aRslt = event.value.split("");
aRslt.splice(event.selStart, event.selEnd - event.selStart, event.change);
var strTest = aRslt.join("");

// Test for valid entry
var rpat = /^\d{0,2}(\/\d{0,2}(\/\d{0,2})?)?$/;
event.rc = rpat.test(strTest);
}
else
{ // In the WillCommit phase we want to validate the whole thing exactly
var rpat = /^(\d{2}\/\d{2}\/\d{2})?$/;
event.rc = (event.value == "") || rpat.test(event.value);
}
sgrossm
Registered: Mar 3 2009
Posts: 5
Is there a way to set a field so that the dashes for the social security number are visible even before a user starts to type in their social security number?

Thanks!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Only you write your own custom format, keystroke, and validation scripts.

George Kaiser