Solved

Java - IBAN account validation

Posted on 2007-03-23
10
3,493 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

808 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