Solved

Java - IBAN account validation

Posted on 2007-03-23
10
3,553 Views
Last Modified: 2012-05-05
Hello,
I looking for a Java methode able to validate an IBAN account and a Belgium account (xxx-xxxxxx-xx).
Thank you.
Mathieu.
0
Comment
Question by:NBBPR05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 18779433
Try

"BE\\d{2}[ ]\\d{4}[ ]\\d{4}[ ]\\d{4}[ ]\\d{4}[ ]\\d{4}[ ]\\d{4}|BE\\d{26}"
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18779494
public static boolean isValidIBAN(String str)
{
      str = str.replaceAll("\\s+", "");
      return Pattern.matches("([A-Z]{2}?[0-9]{14}?)", str);
}

public static boolean isBelgiumAcct(String str)
{
      return Pattern.matches("(\\d{3}?)-(\\d{7})?-(\\d{2}?)", str);
}
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18779515
A typo above, should be
return Pattern.matches("(\\d{3}?)-(\\d{7}?)-(\\d{2}?)", str);

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:owenli27
ID: 18779579
>> looking for a Java methode able to validate an IBAN account..
Are you asking for String format validation or official IBAN validation, such as move first 4 digitals to end and then convert B to 11 and E to 14, then apply MOD 97-10, etc...
0
 

Author Comment

by:NBBPR05
ID: 18779725
I just have to know if an account valid is:
just format, just length, just modulo, etc.
I don't have to create an account.
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18780038
change reluctant quantifiers to possessive ones for safe reason.
return Pattern.matches("([A-Z]{2}+[0-9]{14}+)", str);
return Pattern.matches("(\\d{3}+)-(\\d{7}+)-(\\d{2}+)", str);
0
 

Author Comment

by:NBBPR05
ID: 18780570
owenli27:>> looking for a Java methode able to validate an IBAN account..
>Are you asking for String format validation or official IBAN validation, such as move first 4 digitals to >end and then convert B to 11 and E to 14, then apply MOD 97-10, etc...

I think it's the correct way to solve my problem
0
 
LVL 9

Assisted Solution

by:owenli27
owenli27 earned 250 total points
ID: 18781256
public static boolean isValidBelgianBBAN(String str)
{
      return Pattern.matches("(\\d{3}+)-(\\d{7}+)-(\\d{2}+)", str);
}
      
public static boolean isValidIBAN(String str)
{
      str = str.replaceAll("\\s+", "");
      if( Pattern.matches("([A-Z]{2}+[0-9]{14}+)", str))
               {
                     String convertedStr = str.substring(4) + Character.getNumericValue(str.charAt(0)) + Character.getNumericValue(str.charAt(1)) + str.substring(2, 4);
            long theCheckDigits = Long.parseLong(convertedStr)%97;
            return (theCheckDigits == 1)? true: false;
      }
      else{
            return false;
      }
}
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 74
null output 3 42
going to wrong jsp page 2 47
batch vs regular insert in spring DAO 2 22
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question