Text Field allow to only specific character

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, How to, PDF forms

Views

116

Likes

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

Text Field allow to only specific character

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, How to, PDF forms

Views

117

Likes

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

Likes

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
Reply
Loading...
Jan 14, 2020 1
ls_rbls LATEST
Jan 19, 2020

Copy link to clipboard

Copied

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

 

 

 

 

Likes

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
Reply
Loading...
Jan 19, 2020 0