Solved

Java - IBAN account validation

Posted on 2007-03-23
10
3,589 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

738 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