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

Arbitrary mask more than one format

Explorer ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Hello! How might I be able to allow for two acceptable formats in a field? I'm have an elementary understanding of the arbitrary mask feature. The two formats are as follows:

 

Format 1: A999999999 (one letter & nine numbers)

Format 2: AA999999999 (two letters & nine numbers)

 

Thank you in advance!

TOPICS
JavaScript , PDF forms

Views

5.5K

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Aug 20, 2021 Aug 20, 2021

Try this as validation script:

var str = event.value;
var reg = /^[a-zA-Z]{1,2}[0-9]{9}$/;
var r = reg.test(str);
if(!r)
app.alert("Your message goes here",3);

 

Votes

Translate

Translate
Community Expert , Mar 13, 2024 Mar 13, 2024

Try this as custom keystroke script:

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

Votes

Translate

Translate
Adobe Employee ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Hi there

 

Hope you are doing well and sorry for the trouble. As described,you want to be able to allow for two acceptable formats in a field and want to user arbitrary mask format in the PDF form.

 

For more information about arbitrary mask format, please check the description under 'Format tab for form field properties' section of the help page - https://helpx.adobe.com/acrobat/using/pdf-form-field-properties.html and see if that works for you.

 

Regards

Amal

Votes

Translate

Translate

Report

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
Explorer ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

I read a post that said to allow for multiple formats you need to use a custom script using the RegExp object for testing is possible format. Does this sound correct? Thank you.

Votes

Translate

Translate

Report

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
Adobe Employee ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Hi there

 

You may use the custom format using the JavaScript in the PDF form. For more information about using the JavaScript please check the help page https://acrobatusers.com/tutorials/javascript_console/

 

Regards

Amal

Votes

Translate

Translate

Report

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 ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Try this as validation script:

var str = event.value;
var reg = /^[a-zA-Z]{1,2}[0-9]{9}$/;
var r = reg.test(str);
if(!r)
app.alert("Your message goes here",3);

 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 20, 2021 Aug 20, 2021

Copy link to clipboard

Copied

Thank you. It works great!

Votes

Translate

Translate

Report

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
New Here ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

I tried to adjust this to fit my use case but can't seem to get it to work right... first off, when I click a reset form button that I have, the app alert message come up and would like to have a valid condition of the text box being empty. Basicly I need:

 

Format 1 = blank text Box

Format 2 = 9999 (4 numbers)

Format 3 = 9999AA (4 numbers and 2 letters)

 

When I try to specify these conditions, it seems to accept 9999 or 9999A or 9999AA... I need it not to accept 9999A

Votes

Translate

Translate

Report

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 ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

Try this as custom keystroke script:

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

Votes

Translate

Translate

Report

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
New Here ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

Works perfectly!

Votes

Translate

Translate

Report

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Sorry to revive and hijack this thread, but I am looking for the same thing, but to accept only standard social security numbers or company EINs.  This should be formatted like this:

 

999-99-9999

99-9999999

 

As you can see, it is the same amount of digits, but the formatting will look quite different.  If you could please advise on how to add an "or" using an arbitrary mask, or help me adjust the Java validation script above, I would really appreciate it!

Votes

Translate

Translate

Report

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

LATEST

Try this:

var str = event.value;
var reg = /^\d{3}-\d{2}-\d{4}$|^\d{2}-\d{7}$/;
var r = reg.test(str);
if(!r && str !== ""){
event.rc = false;
app.alert("Your message goes here",3);}

Votes

Translate

Translate

Report

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