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

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

Community Beginner ,
Mar 22, 2019 Mar 22, 2019

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)

TOPICS
PDF forms
2.4K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 22, 2019 Mar 22, 2019

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)

View solution in original post

Translate
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 22, 2019 Mar 22, 2019

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

Translate
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 ,
Mar 22, 2019 Mar 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.

Translate
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 ,
Mar 22, 2019 Mar 22, 2019

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

Translate
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 ,
Mar 22, 2019 Mar 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.

Translate
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 22, 2019 Mar 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.

Translate
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 ,
Mar 22, 2019 Mar 22, 2019

Thanks. I'll try it out.

Translate
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 ,
Mar 22, 2019 Mar 22, 2019

Unfortunately, that didn't work when placed in the Validate > Run custom validation script area nor the Format > Custom Keystroke Script of the Text Field Properties

Thanks anyway.

Translate
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 22, 2019 Mar 22, 2019

Worked fine for me. What happens when you try it? Also, did you edit the code in any way? If so, how?

Translate
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 ,
Mar 22, 2019 Mar 22, 2019

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)

Translate
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 22, 2019 Mar 22, 2019

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)

Translate
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 ,
Mar 22, 2019 Mar 22, 2019

I appreciate your assistance, but neither pieces of code work for me.

Thanks anyway.

Translate
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 ,
Mar 22, 2019 Mar 22, 2019
LATEST

I take that back. The code: event.rc = /^[ACD]?$/.test(AFMergeChange(event));
is functioning as only allowing an A C or D

Thank you very much

Translate
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