Skip to main content
Participant
June 30, 2022
Answered

IBAN

  • June 30, 2022
  • 1 reply
  • 629 views

Bonjour,

Ce qui est classique, je dois vérifié si l'IBAN (ou tous autres) est correct.

Existe-t-il des solutions en CF ?

Sinon comment s'y prendre ?

Merci par avance

 

Hello,

What is classic, I have to check if the IBAN (or any others) is correct.

Are there solutions in CF?

Otherwise how to go about it?

thanks in advance

This topic has been closed for replies.
Correct answer BKBK

You will find ColdFusion code to verify IBAN at cfml.de.

 

Quite generous of Christian Henkel. If the code helps you, then please thank him at info[at]cfml.de.

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
June 30, 2022

You will find ColdFusion code to verify IBAN at cfml.de.

 

Quite generous of Christian Henkel. If the code helps you, then please thank him at info[at]cfml.de.

BKBK
Community Expert
Community Expert
July 3, 2022

@Jean-Marie22691987kfb3 , please note that, Google Translate interferes with the code, introducing errors! For example, the translation into French or English results in

 

REfind("[AZ][AZ]", local.country) == 0

 

which is wrong. 

 

The correct statement is of course:

 

REfind("[A-Z][A-Z]", local.country) == 0

 

<cfscript>
/*	
Origine: https://www.cfml.de/index.cfm?CFID=244157468&CFTOKEN=99092613&at=cf_talk&pt=Forum_Detail&forum_id=304CF7E8-ED9B-9AFC-987D7980EC711985

Auteur: Jens, 13.12.2013 10:12

Je viens d'écrire deux fonctions qui vérifient la structure de l'IBAN et du BIC.
Pour que la roue n'ait pas à être réinventée encore et encore, je poste le code ici pour les développeurs intéressés.
Le code peut être utilisé librement.
	
*/	
	

	
/**
* Vérifie si la chaîne peut être un IBAN
*
*/
public boolean function isIBAN (required string iban) {
	// offset pour convertir les lettres en chiffres
	local.offset = 55;
	
	// Prépare
	arguments.iban = ucase(arguments.iban);
	arguments.iban = replace(arguments.iban, " ", "", "all");
	local.len = len(arguments.iban);
	
	// Vérifie la longueur
	if ( local.len > 34 or local.len < 15)
	return false ;
	
	// Vérifie le code pays
	local.country = left(arguments.iban, 2);
	if ( REfind("[A-Z][A-Z]", local.country) == 0 )
	return false ;
	
	// Tester la somme de contrôle
	local.checksum = mid(arguments.iban, 3, 2);
	if ( REfind("[0-9][0-9]", local.checksum) == 0 )
	return false ;
	
	// Convertit le code pays en nombre
	local.numericCountry = toString( asc(local.country) - local.offset ) & toString( asc( right(local.country, 1) ) - local.offset );
	
	local.numbers = "" ;
	for (i = 5; i <= local.len; i = i + 1) {
		local.c = mid(arguments.iban, i, 1);
		if ( isNumeric(local.c) ) {
			local.numbers = local.numbers & local.c;
		} else {
			// Convertit les lettres en nombres
			local.numbers = local.numbers & toString( asc(local.c) - local.offset );
		}
	}
	
	// Coldfusion ne peut pas gérer les grands nombres, mais Java le peut!
	local.bigInt = createObject( "java", "java.math.BigInteger" ).init(	javaCast( "string", local.numbers & local.numericCountry & local.checksum ) );
	local.modBase = createObject( "java", "java.math.BigInteger" ).init( javaCast( "string", "97" ) );
	
	// Calcule modulo
	local.result = local.bigInt.mod( local.modBase ).toString();	
	if (local.result != "1")
	return false;
	
	// Tout va bien
	return true;
}
</cfscript>

isIBAN("FR14 2004 1010 0505 0001 3M02 606"): <strong><cfoutput>#isIBAN("FR14 2004 1010 0505 0001 3M02 606")#</cfoutput></strong>
BKBK
Community Expert
Community Expert
July 7, 2022

Hi @Jean-Marie22691987kfb3 ,

Could you please let us know whether the code meets your requirements.