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

Changing Characters to Lowercase

Community Beginner ,
Sep 29, 2023 Sep 29, 2023

I need help with a script to change a specific character to lowercase if it was typed in uppercase in a field. Example: 24X12X6 I need just the X's to be changed to lowercase when a button is pressed, only if a number is before and after it. Thanks!

TOPICS
Acrobat SDK and JavaScript
888
Translate
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 ,
Sep 29, 2023 Sep 29, 2023

As the field's custom Validation script enter this:

event.value = event.value.toLowerCase();

Translate
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 ,
Sep 29, 2023 Sep 29, 2023

Sorry, I might have read it too quickly... Do you expect there to be other (non-numeric) characters in the field?

Translate
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 Beginner ,
Sep 29, 2023 Sep 29, 2023

I actually copied and pasted my question in to ChatGPT and it gave me almost exactly what I needed.

 

// Get the input field value
var inputField = this.getField("Description");
var inputValue = inputField.value;

// Use a regular expression to find and replace 'X' with 'x' when surrounded by numbers
var replacedValue = inputValue.replace(/(\d)X(\d)/g, '$1x$2');

// Update the input field with the modified value
inputField.value = replacedValue;

 

Thank you though!

Translate
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 ,
Sep 29, 2023 Sep 29, 2023

Where are you planning on using this script? Will it be on the field where the text to be converted will be placed?

If so you'll need to make some changes. The script you have will only work from outside the field.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 Beginner ,
Sep 29, 2023 Sep 29, 2023
LATEST

It's triggered from a button outside of the field that also triggers a number of other things. It works.

Translate
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