Skip to main content
Kelly_LDI
Participating Frequently
October 5, 2018
Question

Add a dash and the number coundt to be from 3 to 5 characters

  • October 5, 2018
  • 2 replies
  • 1644 views

I have a form with a field formatted as 99-99999 and because of this, the filed is requiring 5 characters after the dash.  Some of our numbers are 3 and up to 7 characters long. Including the dash is 8.

Using the format 99-99999, it's requiring the full 8 characters. How can I make this work with just 3 and up to 8 characters?

Thank you,

Kelly

This topic has been closed for replies.

2 replies

Kelly_LDI
Kelly_LDIAuthor
Participating Frequently
October 6, 2018

Do you have an example I could follow? I'm pretty new to the adobe forms.

Thank you,

try67
Community Expert
Community Expert
October 5, 2018

You'll need to write your own keystroke, format and validation script to achieve it.

Kelly_LDI
Kelly_LDIAuthor
Participating Frequently
October 6, 2018

Hello,

I found a script close to what I need and modified it for my use. However, it comes up with an error at line 13 left? I don't think I have the code quite right. Here is what I have;

// call from format script
// format entry to 99-9 or 99-99 or 99-999 or 99-9999 or 99-99999
function twoDash1() {

//Get the value the user entered, as a string
var s = event.value;

//do nothing if the field is blank
if (!s) return

//allow 3  to 8 characters
if (s.length === 3 || s.length === 4 || s.length === 5 || s.length === 6 || s.length = 7 || s.length === 8) {

// Determine the format string to use
var fs = "99-9" += "-9";
if (s.length === 4) fs;
if (s.length === 5) fs;
if (s.length === 6) fs;
if (s.length === 7) fs;
if (s.length === 8) fs;

//display the formated value
event.value = util.printx(fs, s);

} else {

// let the use know something is wrong
app.alert("Please Enter 3 to 8 characters.", 3);
}

// Call from Keystroke script
// Limit entry to digits only
function DigOnlyKS() {

// Get all that is currently in the field

var val = AFMergeChange(event);

//Reject entry if anything but digits
Event.rc AFExactMatch((/\d*/, val);
}

Any help would be appreciated.

Thank you,

Kelly

try67
Community Expert
Community Expert
October 6, 2018

This entire block is incorrect:

var fs = "99-9" += "-9";

if (s.length === 4) fs;

if (s.length === 5) fs;

if (s.length === 6) fs;

if (s.length === 7) fs;

if (s.length === 8) fs;

I think you want to do something like this:

var fs = "99-9";

if (s.length === 4) fs+="9";

if (s.length === 5) fs+="99";

if (s.length === 6) fs+="999";

if (s.length === 7) fs+="9999";

if (s.length === 8) fs+="99999";