capitalize first letter in text field

eugzl

28-09-2016

Hi All.

I design form in LiveCycle and I would like capitalize first letter in Last Name text field. Could someone let me know how to capitalize it in JavaScript?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

mouslander

30-09-2016

I think I finally got this to work. On the Exit event for the field I put:

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

this forces the first letter of each word to UpperCase

Answers (4)

Answers (4)

mouslander

30-09-2016

If you just want to force everything to upper case then just put this on the fields change event:

xfa.event.change=xfa.event.change.toUpperCase();

eugzl

30-09-2016

Hi Bruce. Thanks for replay.

Is possible to capitalize all words in Last Name if it contains: space, hyphen, single quote or combination of letters and those characters? If yes. Can you show how to do it?

Thanks.

_Bruce_Robertson

MVP

29-09-2016

Hi,

You could add the following JavaScript code in the exit event of your text field.

if (!this.isNull)

{

    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 need to do the same hyphenated names or Van Der Valk's and the like you can try this JavaScript in the exit event;

function toTitleCase(textValue) {

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

}  

if (!this.isNull)

{

  
this.rawValue
= toTitleCase(this.rawValue);

}

Regards

Bruce