Skip to main content
Known Participant
January 14, 2020
Question

Text Field allow to only specific character

  • January 14, 2020
  • 1 reply
  • 1657 views

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..

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
January 14, 2020

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

ls_rbls
Community Expert
Community Expert
January 19, 2020

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/td-p/8851326

 

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: