Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
Adobe Summit 2023 | Complete list of AEM Sessions & Labs
SOLVED

How to make the first letter in a text field capitalized

Avatar

Level 4

Is there a way for me to make the first letter in a field capital if the user forgets to make it capital? For example, in my form there is a field for the first name. I'd like to enter some type of Java Script so when the user tabs off the field & the first letter is not capital, it will make it capital. If I don't have to use Java Script that will be fine too.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If it is just a one word value then you could use this in the exist event;

this.rawValue

= util.printx(">?<*",this.rawValue);

This changes the first character (represented by the ?) to uppercase (represented by the >) and all trailing characters (represented by the *) to lowercase (represented by the <).

If you wanted something more general ... if they could also enter a middle name then you could call a function like;

function

toTitleCase(textValue)

{

  return

textValue.toLowerCase().replace(/\b[a-z]/g, function replacer(match) { return match.toUpperCase(); });

}

This uses a regex to change all lowercase letters following a word boundary to uppercase.

Bruce

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

Hi,

If it is just a one word value then you could use this in the exist event;

this.rawValue

= util.printx(">?<*",this.rawValue);

This changes the first character (represented by the ?) to uppercase (represented by the >) and all trailing characters (represented by the *) to lowercase (represented by the <).

If you wanted something more general ... if they could also enter a middle name then you could call a function like;

function

toTitleCase(textValue)

{

  return

textValue.toLowerCase().replace(/\b[a-z]/g, function replacer(match) { return match.toUpperCase(); });

}

This uses a regex to change all lowercase letters following a word boundary to uppercase.

Bruce

Avatar

Level 4

I couldn't get that code to work. Does anyone know of any JavaScript code to make the first letter in each text box capitalized?

Avatar

Level 4

The 1st example in Bruce's post works perfectly. I think that is exactly what you are looking for. Just put the following code into the 'exit' event of your field and set the Language drop-down to JavaScript:

this.rawValue = util.printx(">?<*",this.rawValue);

As soon as you exit the field the first letter is set to uppercase. I just tested it right now and it worked nicely.

Avatar

Level 7

I found this Formcalc script in another forum:

Surname = Concat(upper(Left(Surname,1)),lower(Right(Surname,Len(Surname)-1)))

Change Surname to your field name

Here's a link to the thread:

http://forums.adobe.com/thread/336179

Avatar

Level 7

I tested this script, there's an error in it. It should be:

Surname = Concat(Upper(Left(Surname,1)), Lower(Right(Surname,Len(Surname)-1)))


again with Surname being the field name. This script caps the first letter in the field and makes all other letters lowercase.

Avatar

Level 1

Just wanted to thank you for your detailed answer. It worked for me too