How to force alpha or numeric inside text fields - LiveCycle Designer 9.0 | Community
Skip to main content
November 9, 2010
Solved

How to force alpha or numeric inside text fields - LiveCycle Designer 9.0

  • November 9, 2010
  • 16 replies
  • 21322 views

I am creating a form that requires City, State and Zip.  I need to make sure that users do not put City, State and Zip into the City field; which someone so nicely pointed out to me as a problem with the form.  Anyway, what I am looking for is a way to force the user to only be able to enter alpha characters into the City text field.  I had glanced at the "Validation Patterns" OOTB functionality but I could not find anything listed that would complete the requirement.


Thank you,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by radzmar

You can use regular expressions in the change:event of the textfield to limit the characters that can be typed in.

Will allow only digits and the characters A-Z and a-z

if (xfa.event.newText.match(/[^A-Za-z0-9]/))      

{

xfa.event.change = "";

}

16 replies

New Participant
May 5, 2015

Hey,

How do i avoid space as my first character? I'd want to restrict user from entering space as my first charcter in a text field.

Thanks,

Radhika

New Participant
November 20, 2014

this code won't work with my dynamic xml form. Is there a different code to make this work for dynamic xml forms? This works only if my form is saved as a static pdf.

radzmar
New Participant
November 10, 2010

Adding a space to the regualar expression will do the trick.

if (xfa.event.newText.match(/[^A-Za-z0-9 ]/))     

{

xfa.event.change = "";

}

November 9, 2010

I did run into one issue in the fact that I cannot add a space now to allow for City names that have more than one word.  What can I add to allow this space in the field?

Thank you,

November 9, 2010

Thank you very much for the quick response to this question.  I used your example and tweaked it just a little to make it allow only alpha characters and then to convert to upper case.  The result that worked was this.

if

(xfa.event.newText.match(/[^A-Za-z]/))

{

xfa.event.change

= "";

}

xfa.event.change

= xfa.event.change.toUpperCase();

Thank you again for your help.

radzmar
radzmarAccepted solution
New Participant
November 9, 2010

You can use regular expressions in the change:event of the textfield to limit the characters that can be typed in.

Will allow only digits and the characters A-Z and a-z

if (xfa.event.newText.match(/[^A-Za-z0-9]/))      

{

xfa.event.change = "";

}