• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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.   

TOPICS
Acrobat SDK and JavaScript

Views

727

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 07, 2022 Apr 07, 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();
	}
}

Votes

Translate

Translate
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

Changing the value.  I copy the persons name from a different form into my form.  I need the field to auto format to upper case last name and lower case first name (with capital at the start of course).   It can be just the way it's presented that changes as long as it stays that way when it's printed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

Sorry, I mean i need the value to auto fomat

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

I found this in the properties 

Hall23939010crcs_0-1649325246126.png

Just need the script to go in here

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

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();
	}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

That worked perfectly!!!!   your amazing 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2022 Apr 07, 2022

Copy link to clipboard

Copied

Hi,

It's correct only the first name is only composed with one name, else you must write something like that:

Note: I modified the previous script if you are using composed first names with hyphen.

 

var theName=event.value.split(",");
if (theName.length>1) {
	var firstName=theName[1].toLowerCase();
	for (var i=0; i<firstName.length-1; i++) {
		if (firstName[i]==" " || firstName[i]=="-") {
			firstName=firstName.substr(0,i+1)+firstName.substr(i+1,1).toUpperCase()+firstName.substr(i+2);
		}
	}
	event.value=theName[0].toUpperCase()+","+firstName;
} else event.value=event.value.toUpperCase();

 

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

Thank you 🙂   That is fantastic!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines