-3

I am trying to write a java program that verifies the validity of a bank account number in Algeria, and I was checking the web for formula, and I found a piece of javascript (that I could not understand).

Here is the code:

function validateFormRIB() {
  var x = document.forms["formrib"]["rib"].value;
  if ((!/^\d+$/.test(x))||(x.length!=20)) {
    alert("Le RIB doit comporter exactement 20 caractères numériques");
    return false;
  }
}

My question is what is the formula used for the computation?

Here is the link to the web page : http://www.babalweb.net/finance/verificateur-rib-releve-identite-bancaire-algerie.php

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Ism Blk
  • 3
  • 2
  • 2
    It's just a regex that checks that the code is only made of digits and its length is 20 digits. – Federico klez Culloca Jul 15 '20 at 08:54
  • 1
    @Teemu OP is trying to write a Java application and has found a piece of JavaScript reference code. Don't see the problem. – Robby Cornelissen Jul 15 '20 at 08:56
  • @RobbyCornelissen Knowing Java doesn't seem to help to solve this problem, though. – Teemu Jul 15 '20 at 08:57
  • @RobbyCornelissen - The problem is that while that is the task that the OP is trying to perform, what he is actually asking is for someone to explain a "formula" written in Javascript. Tags should be relevant to the actual question being asked ... – Stephen C Jul 15 '20 at 08:58
  • @StephenC I understand that, but 1) that doesn't warrant a snarky comment insinuating that OP doesn't know what language they're using; 2) while the question asks for a formula, knowing what language this formula needs to be implemented in can lead to good suggestions. – Robby Cornelissen Jul 15 '20 at 09:06
  • Ah yes. But if you do see the problem, you shouldn't say "I don't see the problem". The problem (tag misuse) is real ... whether or not the comment was snarky. There are better ways to deal with snarky comments; i.e. mod flag them. – Stephen C Jul 15 '20 at 09:15

1 Answers1

0

The "formula" you refer to is (I presume) this part

(!/^\d+$/.test(x))||(x.length!=20)

It has two parts:

(!/^\d+$/.test(x))

and

(x.length!=20)

The first part is a pattern match. It testing to see if the string in the variable x matches the regular expression /^\d+$/. That regex means

/    # start of regular expression
^    # match the start of the string
\d   # match one digit
+    # the previous pattern is matched one or more times
$    # match the end of the string
/    # end of regular expression.

In other words, "match a string that consists of one or more digits".

The second part is testing the string length.

Putting it all together, in context:

IF variable 'x' does not consist of one or more digits 
OR IF it does not have a length of 20
THEN show and 'alert' popup and return false.

The validation "formula" is easy to translate into Java ... or any other language with regex support.

However, it should be obvious that not every 20 digit number is actually a real Algerian bank account number.

(For what it is worth, the Wikipedia page on International Bank Account Numbers (IBANs) has a summary of formats for a number of countries. But it doesn't say anything more about Algerian bank numbers except that they are 20 digits.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Stephen C Thank you very much for your answere, and yes I checked the wikipedia page for IBAN before my post here, and I did not found any think that do the math , the link that I had joined with my question do exactly what I need. well Thank you again, I will code it in java while waiting for the formula the check the account number with the controle key, Thnak you – Ism Blk Jul 15 '20 at 12:43
  • One source I found implied that the first 3 digits are a bank code and the last two digits are check digits of some kind. That's all I could find in English. – Stephen C Jul 15 '20 at 15:33
  • I found that formula, Contorle_key = ((89*bank_code+15*agency_code+3*account_number)%97) where controle_key = last 2 digits, bank code = integer value of first 3 digit , agency code = Integer value of next 5 digits, account number the digits from position 9 to 18. however this method is not active now, they change it, and there is no update on the used method today!! unfortunatelly, well, I am glad to talk to you again dear friend – Ism Blk Jul 16 '20 at 15:14