Skip to main content
Inspiring
June 14, 2024
Answered

Convert text to lowercase

  • June 14, 2024
  • 1 reply
  • 685 views

I have two fields - Text1 and Text2.  Text1 is set to capitalize whatever is entered into it with the following custom validation script:  event.value = event.value.toUpperCase();

 

Text2 is set to copy into it whatever is entered into Text1 with the following custom calculation script:  getField("Text2").value = getField("Text1").valueAsString;

 

I am looking for custom validation script that will convert Text2 to capitalize only the first letter of each word that is entered in Text1.  For example, if "OHIO" is entered into Text1, I would like Text2 to show "Ohio".  If "NEW JERSEY" is entered into Text1, I would like Text2 to show "New Jersey".

 

Thanks.

This topic has been closed for replies.
Correct answer PDF Automation Station

Use the following custom validation script:

 

function toTitleCase(str) 
{
return str.replace(
/\w\S*/g,
function(txt) 
{
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}

event.value=toTitleCase(event.value);

1 reply

PDF Automation Station
Community Expert
Community Expert
June 14, 2024

Use the following custom validation script:

 

function toTitleCase(str) 
{
return str.replace(
/\w\S*/g,
function(txt) 
{
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}

event.value=toTitleCase(event.value);
BrianG934Author
Inspiring
June 14, 2024

Works great.  Thanks!