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

Text Field allow to only specific character

Participant ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

Hi, i want to add a condition to a text field. so it should only allow to type "Y" , "N" or "U". can u pls help me to manage this work. thanks..

TOPICS
Acrobat SDK and JavaScript

Views

1.0K

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 ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

Does it needs to be achieved with a script?

 

You can achieve that with a  a dropdown menu. 

 

Just add the Y , N , U options in the  list items and uncheck the box that says Allow users to type, then lock the field

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 ,
Jan 19, 2020 Jan 19, 2020

Copy link to clipboard

Copied

LATEST

Hi, 

 

Just wondering if you were able to resolve your this exercise.

 

If your still looking for  a condition I found this thread: https://community.adobe.com/t5/acrobat/how-to-allow-only-certain-characters-to-be-typed-in-a-field/t...

 

So you can modify your script like 

 

 

 

if (event.change) {

     event.rc = /^[N,n,U,u,Y,y]/.test(event.change);

}



//if you need to restrict the N, U and Y letters to uppercase only modify the script above like this:

if (event.change) {

     event.rc = /^[N,U,Y]/.test(event.change);

}



//PLAYING AROUND WITH THIS LITTLE SCRIPT I NOTICED THAT THIS ALSO WORKS

if (event.change) {

     event.rc = /^[N,n,U,u,Y,y]/.test(event.change);

}

event.change = event.change.toUpperCase(); 

 

 

 

If you are using the dropdown menu method like I suggested in my first reply, and you are allowing users to also enter their own text and need to  restrict the them  to  typen only  one of those three letters see image below:

 

ROUNDING1.png

 

 

 

 

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