Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
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

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

TOPICS
Acrobat SDK and JavaScript , Windows
3.9K
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

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

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

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.

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

I am a newbie to JavaScript:(

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

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)');

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

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?

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

Exactly!!

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

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

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

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

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

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

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

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.

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 ,
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);

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

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

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