Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

How to Create Text Field Which Accepts (Only Alphabates No Digits or Numbers)

Avatar

Level 2

hey guys,

i just want know How to Create Text Field Which Accepts (Only Texts No Digits or Numbers)?

i want to insert validation that, field only accepts alphabates no number or digits are accepted!


thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 5

In Designer, click on the field you need to validate and open the script window, set the Show drop-down list to validate in the drop-down list and place the code inside the script window. Make sure the Language is Javascript and Run At is set to Client. If you cant see the script window goto Window->Script Editor Menu item.

View solution in original post

12 Replies

Avatar

Level 5

For alphabetical characters only, use the following javascript on the validate event of the text field

var r = new RegExp("^[a-z]*$");

var result = r.test(this.rawValue);

if (result == true)

    true;           

else               

    false;  

Also, set the Validation Script Message properties in the Object->Value Tab

Avatar

Level 2

Im not getting you.

where to put this script that you have coded?

             

Avatar

Correct answer by
Level 5

In Designer, click on the field you need to validate and open the script window, set the Show drop-down list to validate in the drop-down list and place the code inside the script window. Make sure the Language is Javascript and Run At is set to Client. If you cant see the script window goto Window->Script Editor Menu item.

Avatar

Level 2

Yes, you have answered my question 90%,

but im still able to insert digits (or integer or number values) into that field, it shows me error message when i move over to another field.

Avatar

Level 5

Not sure if you are looking for an actual validation for the field (i.e. show an error and stop the user from moving to the next field) or just a filter in the field (i.e. no message and just stop characters being entered). From the original message i was assuming you were looking for a validation.

If you want to use a message box validation and return to the field containing the error, use the following -

On the exit event

var r = new RegExp("^[a-z]*$");

var result = r.test(this.rawValue);

if ( result != true )

{

    xfa.host.messageBox( "Enter alpha characters only" );

    xfa.host.setFocus( this );

}

If you are looking for a filter then, use the following on a change event of the field

var r = new RegExp("^[a-z]*$");

var result = r.test(xfa.event.change);

if ( result != true )

{

    xfa.event.change = "";

}

this will probably only work in pdf and some versions of reader had a bug with this so make sure you are on 10.1.2 to test this. see http://forums.adobe.com/thread/910259

Avatar

Level 2

i want a script that dont allow even to let user type numeric values.

ie. if i take numeric field it wont allow me even to enter alphabates. i want reverse thing, i dont want to allow user to type or insert numeric values to text field

Avatar

Level 5

Try the second example in the previous message. That will disable any non-alpha input. Put it on the change event and remove any other event code.

Avatar

Level 2

thanks mate,

i was putting the code in validate event!

what is the difference between change and validate events?

sorry if its off topic.

thanks again

Avatar

Level 5

The change event is fired each time a user interacts with an object using keystroke, paste, list selection, select/deselect check bos, or change radio button. The validate on the other hand only fires when the field losses when you tab to the next field for example

Avatar

Level 2

your script is not allowing me to enter a "Blank Space".

Avatar

Level 5

It is only a sample of matching text. You do need to update the regular expression to match your requirements. So if you wish to allow spaces in the input, you would add this to the regular expression as follows

var r = new RegExp("^[a-z' ']*$");

also wouldnt do uppercase for example, so you would ass A-Z to the regexp ( i.e. [a-zA-Z' ']) and so on