Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You'll need to write your own keystroke, format and validation script to achieve it.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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";
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
It should start with:
event.value =
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Where is the end of function twoDash1?
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
Sorry, my bad... The last line should not be what I said before, but this:
event.rc = AFExactMatch(/\d*/, val);
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
Yes, of course, you still need the closing curly bracket...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
What's wrong with the solutions you got?
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
Do you have an example I could follow? I'm pretty new to the adobe forms.
Thank you,
Find more inspiration, events, and resources on the new Adobe Community
Explore Now