Skip to main content
Participating Frequently
March 22, 2019
Answered

Can a text field be set to accept only specific letters?

  • March 22, 2019
  • 4 replies
  • 2352 views

I'm not a developer, although I can hack through code. I can't seem to find an answer for what seems to be a basic question.
I'm trying to set a a text field to accept only specific capitalized letters.
Any help would be wonderful.
Thanks in advance
(Acrobat Pro DC)

This topic has been closed for replies.
Correct answer try67

I didn't alter the code except to change the input characters in the brackets to [ACD].
The code didn't change anything; text field functioned as a text field.

if (event.value) event.rc = /^[ACD]$/.test(event.value)


Just to clarify: This code will not prevent the user from entering the not-allowed characters, but it will reject the new value once you exit the field. If you want it to only allow them to enter those characters then you can use this as the Keystroke script:

event.rc = /^[ACD]?$/.test(AFMergeChange(event));

(It's normal if the script disappears once you enter it. It should still work)

4 replies

try67
Community Expert
Community Expert
March 22, 2019

You can do it with the following custom validation script:

if (event.value) event.rc = /^[AVXZBD]$/.test(event.value)

Edit: To clarify, the allowed letters are those between the square brackets.

tk7170Author
Participating Frequently
March 22, 2019

Thanks. I'll try it out.

tk7170Author
Participating Frequently
March 22, 2019

I wanted to avoid a dropdown b/c the field is wide enough for one letter and the dropdown arrow would be problematic.

sergiy2511
Participating Frequently
March 22, 2019

I think you would need to go for regular expressions in the field validation

jane-e
Community Expert
Community Expert
March 22, 2019

Would it would to create a drop down list with those specific capitalized letters?

tk7170Author
Participating Frequently
March 22, 2019

I wanted to avoid a dropdown b/c the field is wide enough for one letter and the dropdown arrow would be problematic.