Print Page | Close Window

Validating Routing Numbers - Algorithm

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1560
Printed Date: 21 Nov 2019 at 5:32pm
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Validating Routing Numbers - Algorithm
Posted By: skowalczyk
Subject: Validating Routing Numbers - Algorithm
Date Posted: 19 May 2015 at 2:27pm
Good Morning,
 
I'm trying to validate ABA Routing Numbers within a field on a PDF.  I've tried various ways (one way is below).  I can't seem to get it to work.  Any help will be greatly appreciated.
 
// Check each digit and calculate the total.
  n = 0;
  for (i = 0; i < t.length; i += 3) {
    n += parseInt(t.charAt(i),     10) * 3
      +  parseInt(t.charAt(i + 1), 10) * 7
      +  parseInt(t.charAt(i + 2), 10);
  }
 
// If the resulting sum is an even multiple of ten (but not zero),
// the aba routing number is good.
 
  if (n != 0 && n % 10 == 0){
    return true;
  else
    return false;
}



Replies:
Posted By: BAlheit
Date Posted: 19 May 2015 at 2:48pm
What happens when you use the code?


Posted By: skowalczyk
Date Posted: 19 May 2015 at 3:02pm
Absolutely nothing happens.  No errors, no pop-up alerts, nothing.  :-(
 
Thanks!


Posted By: skowalczyk
Date Posted: 19 May 2015 at 3:10pm
Basically, I'm trying to accomplish this:
 
http://www.brainjar.com/js/validation/default.asp - http://www.brainjar.com/js/validation/default.asp
 


Posted By: Horndoggie
Date Posted: 19 May 2015 at 3:16pm
Looking at this in the link: Note that even if a number passes this test, it does not necessarily mean that it is valid. The number may not, in fact, be assigned to any financial institution.
Wouldn't it be better to validate against a database of actual banks?  With your method you could get a valid number, but the wrong bank which could lead to huge issues.

-------------
Doug


Posted By: skowalczyk
Date Posted: 19 May 2015 at 3:28pm
Unfortunately, I do not have the ability to validate against a database of actual banks at this time.
 
I was also trying to get / use the "mod 10" algorithm; but, nothing seems to happen.
 
http://en.wikipedia.org/wiki/Luhn_algorithm - http://en.wikipedia.org/wiki/Luhn_algorithm
 
Thanks!


Posted By: BAlheit
Date Posted: 19 May 2015 at 3:51pm
Where did you use the code?


Posted By: skowalczyk
Date Posted: 19 May 2015 at 4:13pm
Within the field.  Calculate > Custom Calculation Script
 
Thanks!


Posted By: try67
Date Posted: 19 May 2015 at 5:42pm
The code needs to be adjusted and then used as a custom validation script, so you could accept or reject the value. Try using this code for that purpose (note I didn't test it, I just used the code you provided as-is, after fixing one error it had):

function validateABARoutingNumber(t) {
    // Check each digit and calculate the total.
      n = 0;
      for (i = 0; i < t.length; i += 3) {
        n += parseInt(t.charAt(i),     10) * 3
          +  parseInt(t.charAt(i + 1), 10) * 7
          +  parseInt(t.charAt(i + 2), 10);
      }
     
    // If the resulting sum is an even multiple of ten (but not zero),
    // the aba routing number is good.
     
    if (n != 0 && n % 10 == 0)
        return true;
      else
        return false;
  
}

if (event.value) {
    event.rc = validateABARoutingNumber(event.value);
}


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: skowalczyk
Date Posted: 19 May 2015 at 6:02pm
Thank you!  I will give it a try.


Posted By: skowalczyk
Date Posted: 19 May 2015 at 6:15pm
It seems to be working.  Thank you, try67!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net