Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Ensure input is all alpha characters?

Avatar

Level 2
My form has some fields that should only have alphbetic characters--no numbers or symbols--but the lengths will vary from a couple of letters to an entire sentence. For example, entering a bunch of cities and counties and peoples' names. The length varies, but all must be alpha characters only.



Thanks.



Buck
7 Replies

Avatar

Former Community Member
On the exit event of the field you want to effect you can run a javascript command to force th etyped in input to Upper case. I believe the command is toUpper().

Avatar

Former Community Member
Hi Paul,



Can u explain the same.

I have taken text field;it takes numerics,symbols as well as alphabets.

How can we validate that the field consists of alphabet only? How the scripting can be done?



i didnt get the use of toupper(),how it will ensure the field consists of only alpha characters.



Thanks



Buddy

Avatar

Former Community Member
The toUpper() is a javascript command that can be applied to a string that woudl return all chars in upper case. If you want to restrict to alpha only then having a mask of text{AAAA} forces a 4 char alpha input. If the number of chars is unknown then you will have to test each char as it is entered. I have script somewhere for this so if you need it let me know.

Avatar

Former Community Member
Hi Paul,



The number of characters is unknown,i need to validate fields like customer name.

I have tried with text{AAA}.But it works only for word length of 3.I need to check for variable length field. Please provide me with the Script.It will be a great help.



Thanks,

Buddy

Avatar

Former Community Member
Hi Paul,

I have one more question.

For better Performance which one is better for a large sized file

1)validation

2)scripting



For variable length character validation is Scripting the only option?



Thanks,

Buddy

Avatar

Former Community Member
If you do not know the length the scripting is your only choice.

Avatar

Former Community Member
You could use a regular expression in the exit event (using JavaScript). The following will return true if the user has entered any combination of spaces and letters (including an entry consisting of all spaces - you may want to handle that scenario as well):



if (!this.rawValue.match(/^[\sA-Za-z]+$/)){

// Handle the error as desired here

}



To learn more about RegExp, check out this tutorial:

http://www.regular-expressions.info/tutorial.html