Skip to main content
Participating Frequently
April 7, 2022
Answered

Formatting name text to Last name uppercase and first name lower case

  • April 7, 2022
  • 1 reply
  • 1378 views

I have a form that has a single name field: "LAST NAME, First name" in the same field. I copy and paste the name in from other source but it comes in all different formatting, sometimes all lower case sometimes in all upper case. Is it possible to have a script that changes the formatting to last name all upper case e.g (SMITH) and first name normal e.g (John) with the comma in between as above? e.g  Name:  SMITH, John.

I have been looking for the right script to use for this for so long.   

This topic has been closed for replies.
Correct answer try67

Try this code:

 

if (event.value) {
	var parts = event.value.split(", ");
	if (parts.length==2) {
		event.value = parts[0].toUpperCase() + ", " + parts[1].charAt(0).toUpperCase() + parts[1].substr(1).toLowerCase();
	}
}

1 reply

try67
Community Expert
Community Expert
April 7, 2022

Are you talking about changing the name of the field, or changing its value?

If the latter, are you talking about changing the actual value, or just how it is presented on the page (its formatting)?

Participating Frequently
April 7, 2022

I found this in the properties 

Just need the script to go in here

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 7, 2022

Try this code:

 

if (event.value) {
	var parts = event.value.split(", ");
	if (parts.length==2) {
		event.value = parts[0].toUpperCase() + ", " + parts[1].charAt(0).toUpperCase() + parts[1].substr(1).toLowerCase();
	}
}