Copy link to clipboard
Copied
Hi all!
I am tryin to make a specific text box on an adobe acobat form be a specific format and only populate numbers. I need the text box to format as xx-xxxxx for a Bankruptcy Case Number. The text field needs to be able to change for multiple numbers. For example, if I need the text field to be 12-34567 and then the next time I compete the form I need it to say 98-76543. If I were to type anything other than this format, the text box won't populate - this would also include any letters that are typed, the text box would won't populate. Only format acceptable is xx-xxxxx. The dash must auto populate as well.
Thanks for you help!
Copy link to clipboard
Copied
The simplest way is to use an Arbitrary Mask:
Copy link to clipboard
Copied
Hope you are doing well and thanks for reaching out.
Disclaimer: I want to clarify that I am not a JavaScript expert. Feel free to attempt implementing the provided code and assess its functionality for your specific situation.
// Get a reference to the text field by its name
var textField = this.getField("YourFieldName");
// Define a regular expression pattern for the allowed format (e.g., only digits and one decimal point)
var pattern = /^[0-9]+(\.[0-9]+)?$/;
// Add an event listener to the text field for user input
textField.setAction("Keystroke", function() {
// Get the current value of the text field
var value = event.value;
// Test the value against the pattern
if (!pattern.test(value)) {
// If the value doesn't match the pattern, clear the field
app.alert("Please enter a valid numerical format.");
event.value = "";
}
});
Make sure to replace "YourFieldName"
with the actual name of your text field. This code will enforce that the text entered into the field matches the specified numerical format (digits with an optional decimal point). If the input doesn't match the pattern, it will display an alert and clear the field.
Hope it will help.
Regards
Amal
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@Amal. Thanks! As I am not a coder, I need to remove the lines with the "//" correct?
Also is the only thing I need to update is the "YourFieldName" with my actual text box name? I only say one "YourFieldName"
Thanks!
Copy link to clipboard
Copied
var textField = this.getField("Case");
var pattern = /^[0-9]+(\.[0-9]+)?$/;
textField.setAction("Keystroke", function() {
var value = event.value;
if (!pattern.test(value)) {
app.alert("Please enter a valid numerical format.");
event.value = "";
}
});
"Case" is my test box
Copy link to clipboard
Copied
Yes, that is correct 'Case' is your test box. you can remove the lines with the "//" as those are the comments within the code for explaining and understanding.
~Amal
Copy link to clipboard
Copied
@Amal. Thanks! Thats what I thought but it doesnt seem to be working.
It still lets me type in letters and doesnt format to xx-xxxxx
Copy link to clipboard
Copied
The simplest way is to use an Arbitrary Mask:
Copy link to clipboard
Copied
@JR Boulay this worked perfectly! thanks!
one follow-up question. Is there a way to change the warning pop-up box? For Example, instead of saying "The value entered does not match the format of the field = "99-99999" it would say "The value entered does not match the format of the field = "xx-xxxxx"
Copy link to clipboard
Copied
"It still lets me type in letters and doesnt format to xx-xxxxx"
This is normal, Amal.'s script doesn't format the value.
Copy link to clipboard
Copied
"Is there a way to change the warning pop-up box? "
No, this requires to use a format function in JavaScript