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

Custom Format Javascript help!

Lande1kn
Registered: Jan 21 2008
Posts: 8
Answered

I want to create a custom format Javascript that will convert a string of 9 letters or numbers (or comination) upon entry to a format such as XXX-XX-XXXX (like a Social Security number only it will allow letters also). I would also like the letters to be automatically capitalized.

Thanks for your help!

-Kristin

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

Go to the field's properties (Rt Click, choose Properties). In the Format tab choose Special and select "Arbitrary Mask." You can look up arbitray mask in the Acrobat help file to see what is available, but for what you want use OO-OOO-OOOO ( letter O, not zero). Then in the Validate tab check the Run Custom Validation script, click the Edit button and enter this line of code-
event.value = event.value.toUpperCase();


Hope that helps,

Dimitri
WindJack Solutions
www.windjack.com
Lande1kn
Registered: Jan 21 2008
Posts: 8
Thanks for your quick response, but it didn't work. I put the arbitrary mask in as OOO-OO-OOOO (the format I want) and tried it. It won't let me type letters at all, only 5 numbers max and it doesn't format them in any way. I added the Caps validation and it still wouldn't let me type letters. Any other suggestions?

Thanks,
Kristin
Lande1kn
Registered: Jan 21 2008
Posts: 8
I tried it again and copied your format exactly (OO-OOO-OOOO) and it worked but I want (OOO-OO-OOOO)...any other suggestions.

Thanks!
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi Kristin,

Not sure- I changed my mask to OOO-OO-OOOO and it works fine here in Acrobat 8 Pro. You do need to make sure you have both the Format and Validate parts completed for the field.

Hope this helps,

Dimitri
WindJack Solutions
www.windjack.com
Lande1kn
Registered: Jan 21 2008
Posts: 8
It's working now! ...Not sure why it didn't before. Must have been user error. :)

Thanks so much for the help and the quick response!

-Kristin
details
Registered: Mar 16 2010
Posts: 1
any ideas how to do the same using javascript as i need to have a different error msg then the default
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you want to use a custom string, then you will need to write some custom JavaScript for the format, validation, and keystroke. Thom Parker in [url=http://www.acrobatusers.com/tutorials/text-matching-regular-expressions]Text matching with regular expressions[/url] shows how to test a string using the RegExp object. But to provide all of this is beyond a simple post.

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The arbitrary mask formatting option is acutually implented with JavaScript under the covers. It uses the "util.printx()" function. Look it up in the Acrobat JavaScript Reference. You can use exactly the same mask you're using now, but with a custom message.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

vbogardus
Registered: Oct 15 2010
Posts: 2
I am exporting data (SSN) from an EMR system into a custom form. When the form field auto populates the SSN, I need it without the dashes.

Example:

Format in EMR System: 123-23-4567

What I need is 123234567 when populating the form field.

Would I need Java Script or is this something I can program an Arbitrary Mask? Please let me know. Thanks

VBogardus

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Assuming you're using a form created in Acrobat and not LiveCycle Designer, you can use the following either as the field's custom Format or Validate script. Use Format if you don't want to alter the underlying field value, and Validate if you do.

event.value = event.value.replace(/-/g, "");