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

551

Likes

translate

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

Most Valuable Participant , 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);

Likes

translate

Translate

Translate
Most Valuable Participant ,
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.

Likes

translate

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:(

Likes

translate

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

Likes

translate

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
Most Valuable Participant ,
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?

Likes

translate

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!!

Likes

translate

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
Most Valuable Participant ,
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...

Likes

translate

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.

Likes

translate

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

Copy link to clipboard

Copied

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

Likes

translate

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.

Likes

translate

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
Most Valuable Participant ,
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);

Likes

translate

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

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

Likes

translate

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