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

Is there a javascript to format a text field to have number format and allow text as well?

New Here ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Is there a javascript to format a text field to have number format and allow text as well?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.9K

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 , Feb 08, 2019 Feb 08, 2019

OK, then you can use this code as the field's custom Format script:

if (event.value && !isNaN(Number(event.value))) AFNumber_Format(2, 1, 0, 0, "", false);

Votes

Translate

Translate
Community Expert ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Not an existing one, but you can certainly write one... The tricky part will be to differentiate between a number and other text, and only apply the formatting to the former.

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

I am a newbie to JavaScript:(

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Is there a javascript to format a text field to have number format and allow text as well?

Below code i found can set the number format, but how to format the field to take a specific value XX. If i enter number it should be formatted in numeric format and should take the character XX as well.

this.getField("fieldname").setAction("Format", 'AFNumber_Format(0, 1, 0, 0, "", false)');

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Do you mean that if you enter "ABC" into the field it should stay the same, but if you enter "5" it should become "5.00" or something like that?

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Exactly!!

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

What about if it's "5 ABC 6"? Or "5ABC6"? This is not a simple task, as you can see...

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

Yeah. I need to have either number with numerical format or a text value.

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

So "5ABC6" should become "5.00ABC6.00"?

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

No. At a time it will be either text or number. If I enter 10000, it should be formatted as 10,000. At some cases I will enter NONE. Usually if I enter text in numeric field, it won’t allow.

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 ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

OK, then you can use this code as the field's custom Format script:

if (event.value && !isNaN(Number(event.value))) AFNumber_Format(2, 1, 0, 0, "", false);

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 ,
Feb 10, 2019 Feb 10, 2019

Copy link to clipboard

Copied

LATEST

Yay!!!! It worked. Thank you so much!!

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