Skip to main content
wayne_98685926
Participant
May 30, 2018
Answered

Text field for numerals or letters only

  • May 30, 2018
  • 2 replies
  • 3311 views

Hi.

I'm trying to get certain fields for numbers only and certain others for letters only. When I open Text Field Properties, there is no option for numbers or letters only. Really stuck! (also, don't have a clue where or how to do coding if needed...!)

Thanks!

This topic has been closed for replies.
Correct answer try67

This can be done using a custom Keystroke script.

For example, this one will only allow numbers:

event.rc = /^\d*$/.test(AFMergeChange(event));

And this one will only allow letters (both lower and upper case):

event.rc = /^[a-z]*$/i.test(AFMergeChange(event));

2 replies

wayne_98685926
Participant
May 30, 2018

Thank you, but I'm not sure how to do this.

How do I apply a custom keystroke script?

try67
Community Expert
Community Expert
May 30, 2018

Right-click the field in Form Edit mode, select Properties, Format, Custom and then click on Edit next to Custom Keystroke Script and paste the code into the window that opens.

It's possible that after you do that the selection will revert back to None. That's OK. Just click on Close and it should work.

wayne_98685926
Participant
May 30, 2018

Thank you for your quick reply. Much appreciated.

.... Problem is, when I go into Properties, I only have 4 tabs, (General, Appearance, Position and Options)! (No Format option!)

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 30, 2018

This can be done using a custom Keystroke script.

For example, this one will only allow numbers:

event.rc = /^\d*$/.test(AFMergeChange(event));

And this one will only allow letters (both lower and upper case):

event.rc = /^[a-z]*$/i.test(AFMergeChange(event));

Participant
January 25, 2023

This is nearly perfect for me.  I would like to use event.rc = /^[a-z]*$/i.test(AFMergeChange(event)); but also allow for a space.  My intent is to use the code in a "City" field.  Some cities, like San Francisco, require a space between two words/letters.  Is this possible?

Participating Frequently
May 6, 2023

Yes, it’s possible:

 

event.rc = /^[a-z\s]*$/i.test(AFMergeChange(event));

 

 Alternatively, if you want to include hyphens for compound words:

 

event.rc = /^[a-z\s-]*$/i.test(AFMergeChange(event));

 

 For non-English Latin-1 alphabets that use diacritics:

event.rc = /^[a-zÀ-ž\s-]*$/i.test(AFMergeChange(event));