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

Arbitrary Mask Question

Participant ,
Nov 02, 2024 Nov 02, 2024

I'm hoping someone can me clean up the following Arbitrary Mask javascript I'd like to use on a form.  My goal is to change it to just 3 alphabet letters.  I can't seem to get the script right.  Here is where i'm at with this and it's not working.

 

if(event.willCommit){
var input = event.value;
var pattern = /^(|\[A-Za-z]{3}$|$/);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}

 

Thank you in advance for any ideas on how to make this work!

TOPICS
How to , JavaScript , Modern Acrobat , PDF forms
898
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 04, 2024 Nov 04, 2024

You don't need JavaScript to do this:

 

 

  • A - Accepts only letters (A–Z, a-z).
  • X - Accepts spaces and most printable characters, including all characters available on a standard keyboard and ANSI characters in 32–126 and 128–255.
  • O - The letter “O” accepts alphanumeric characters (A–Z, a-z, and 0–9).
  • 9 - Accepts only numeric characters (0–9).

 

 

Capture_2411041139.png


Acrobate du PDF, InDesigner et Photoshopographe

View solution in original post

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 ,
Nov 02, 2024 Nov 02, 2024

Use this:

 

var pattern = /^[a-z]{3}$/i);

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
Participant ,
Nov 03, 2024 Nov 03, 2024

Here is what i input and it did not work.

 

if(event.willCommit){
var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}

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 ,
Nov 03, 2024 Nov 03, 2024

Where did you place it? Under which event?

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
Participant ,
Nov 03, 2024 Nov 03, 2024

Right after event value.  I made the text blue below to show you.

 

if(event.willCommit){
var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}}

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 ,
Nov 03, 2024 Nov 03, 2024

No, the full code. Where did you place it under the field? Format? Keystroke? Validation? Something else?

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
Participant ,
Nov 03, 2024 Nov 03, 2024

Oh.  I was trying to place it in the format, custom, custom keystroke but it was taking 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 Expert ,
Nov 03, 2024 Nov 03, 2024

Use just this part as the custom Validation script:

 

var input = event.value;
var pattern = /^[a-z]{3}$/i);
if (!pattern.test(input)) {
event.rc = false;
app.alert("Input must be either 3 alphabet letters, or blank.");}
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
Participant ,
Nov 03, 2024 Nov 03, 2024

First of all, i really appreciate you helping me!

 

I entered in as a validation script and i got a SyntaxErro:  missing : before statement 2: at line 3

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
Participant ,
Nov 03, 2024 Nov 03, 2024

I was playing around with this, looking at some things you've done for others and I came up with this as a custom validation script.  I think this might work.  I also included a pop up for the user instructing them to enter 3 letters.  This is the best i could come up with.

 

if (event.value!="") event.rc = /^[a-z]{3}$/i.test(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 Expert ,
Nov 04, 2024 Nov 04, 2024

You don't need JavaScript to do this:

 

 

  • A - Accepts only letters (A–Z, a-z).
  • X - Accepts spaces and most printable characters, including all characters available on a standard keyboard and ANSI characters in 32–126 and 128–255.
  • O - The letter “O” accepts alphanumeric characters (A–Z, a-z, and 0–9).
  • 9 - Accepts only numeric characters (0–9).

 

 

Capture_2411041139.png


Acrobate du PDF, InDesigner et Photoshopographe
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
Participant ,
Nov 04, 2024 Nov 04, 2024
LATEST

Yes!  This is the answer and 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