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

Custom Formats

Flashmyster
Registered: Dec 9 2007
Posts: 11

Hello Again:

I am designing a form that needs to have a field for a number that is in the follwoing format:

###-###-###

For Example:

123-456-789

I am hoping to be able to enter the number (in this example 123456789) and have the dashes inserted automatically after every third digit. The closest I could find was the Special format for Social security but it is not quite what I am looking for. Therefore I have to use Custom fromat but I do not know the Java script for this.

I would appreciate any help. Thank you.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
In LiveCycle Desinger you enter the format into the appropriate fields for the field's object tab. In Acrobat forms you have to use the JavaScript RegExp object to describe the format and write the custom keystroke, validation and format scripts.

George Kaiser

lkassuba
ExpertTeam
Registered: Jun 28 2007
Posts: 3636
Thom Parker has an example of this custom format (automatic insertion of dashes in SS #) in his article on Formating Text Fields at:
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/formatting_text_fields/

Lori Kassuba is an AUC Expert and Community Manager for AcrobatUsers.com.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Thom's script for the auto insert of the seperator needs to be changed for the the insertation of the seperator after the 3rd and 6th digits and the digits grouped in 3s. So the script for the "Custome Keystroke" becomes:

if(!event.willCommit)
{
/*
This script uses the same value merge and prgressive pattern as the previous field
but it first checks for the entry situations where a hyphen needs to be entered
before the next keystroke and then fixes up the change value
*/
if(/^\d{3}$/.test(event.value) && event.selStart == 3)
event.change = "-" + event.change; // insert after 3 numbers
else if(/^\d{3}-\d{3}$/.test(event.value) && event.selStart == 7)
event.change = "-" + event.change; // insert after 6 digits and "-"

// 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,3}(-\d{0,3}(-\d{0,3})?)?$/;
event.rc = rpat.test(strTest);
} else {
// In the WillCommit phase we want to validate the whole thing exactly

var rpat = /^(\d{3}-\d{3}-\d{3})?$/;
event.rc = (event.value == "") || rpat.test(event.value);
}

George Kaiser