Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 05, 2018 Oct 05, 2018

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

TOPICS
PDF forms
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2018 Oct 05, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 06, 2018 Oct 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2018 Oct 06, 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";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 06, 2018 Oct 06, 2018

Hello,

OK, that seemed to work perfect. However, I'm receiving an error at the last line in the code.

SyntaxError missing ; Before Statement

44: at line 45

This would be the last line of the code:

// 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 4  to 8 characters
if (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";
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";

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

} else {

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

// 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);
}

I'm not sure what it's looking for?

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2018 Oct 07, 2018

It should start with:

event.value =

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 07, 2018 Oct 07, 2018

Hello,

I'm sorry, but I'm not sure where it goes in the code. I tried replacing a few things and also removing a few lines, but cannot get it to work.

please see the second last line.

// 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 === 4 || s.length === 5 || s.length === 6 || s.length === 7 || s.length === 8) {

// Determine the format string to use
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";

//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);
event value = util.printx(fs, s);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2018 Oct 07, 2018

Where is the end of function twoDash1?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 07, 2018 Oct 07, 2018

Hello Bernd,

what I did was copied some java code and tried to modify it for my needs. I am very new to coding with Java and really not sure about the formatting. I have tried to look up my particular example, but only found (1) that I thought might be close.

What I currently have is a text box using the formatting of 99-99999. After I modified the form, I was told that the number could be ##-# and contain up to 5 numbers after the dash. I'm hoping that someone can help me out  with this.

Thank you,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2018 Oct 07, 2018

Sorry, my bad... The last line should not be what I said before, but this:

event.rc = AFExactMatch(/\d*/, val);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 07, 2018 Oct 07, 2018

Hello Try67,

I did have this as the last line and it still comes up with the error

SyntaxError missing ; Before Statement

44: at line 45

with the code;

event.rc = AFExactMatch(/\d*/, val);

the only thing after that is the } and that's where it errors out. I assume this would be needed as being the end of the statement?

Thank you,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2018 Oct 07, 2018

Yes, of course, you still need the closing curly bracket...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 18, 2018 Oct 18, 2018

I ended up creating (2) separate fields to accomplish the xxx-xxxxx field.

I do appreciate the help that I did get, but really thought there would have been more solutions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2018 Oct 18, 2018

What's wrong with the solutions you got?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2018 Oct 20, 2018
LATEST

Hello,

There was nothing wrong with the solutions that were provided by everyone who offered help, I sincerely appreciate the help that was provided. It really did help me out on understanding the procedure. I really had trouble with finding the answer to resolve the issue with the last line where it failed to finish the statement and make it all work.

Again, I sincerely appreciate the help that was provided by you and others.

Thank you,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2018 Oct 05, 2018

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

Thank you,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines