Solved

Java - IBAN account validation

Posted on 2007-03-23
10
3,458 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
countHi2 challenge 7 44
Java and GPO 11 47
what is a "java.lang.System Property"   ? 20 39
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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:

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now