Solved

Java - IBAN account validation

Posted on 2007-03-23
10
3,656 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

635 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