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

Lengh calculation and error message

New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

When using this script I get the error message when I enter in like 3 of the nine numbers I need,

But if i do put in the afterward the 9 numbers the error message does not go away it stays. Also I tried using <= this ths a value reference in Javascrpt am I doing this wrong

Bank_Routing_number is formated as number

 

var cNumString = this.getField("Bank_Routing_Number").valueAsString;

if (cNumString < 9) event.value = " ";

else event.value = "Bank Routing Number Must be 9 Characters";

 

Help would be appricated

TOPICS
Acrobat SDK and JavaScript

Views

277

Likes

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 ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

A string can't be compared to a number. You need to convert it to a number first, like this:

if (Number(cNumString) < 9) event.value = " ";

Likes

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 ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Sorry, that's not actually the issue in your case. In second look I think the problem is you're comparing the value itself, instead of its length. So use this code, instead:

 

if (cNumString.length < 9) event.value = " ";

Likes

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
LEGEND ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

LATEST

U.S. bank routing numbers on include a self checking number. This  can be used to verify that it is a valid number.

Likes

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