Click here to Skip to main content
15,912,665 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to do IBAN Validation via Javascript?
Posted

1 solution

 
Share this answer
 
Comments
Kandiya 28-Apr-15 3:35am    
I want to update the below IBAN validation suited for all countries other than UAE alone???
<script>
//var IBAN = "DE12500105170648489890";

//var IBAN = "GB82WEST12345698765432";
var IBAN="AE260211000000230064016";
app.alert(IBAN);

if (IBAN == "") {
app.alert("Please Enter IBAN Value");
this.getField("txtIBAN").setFocus();
exit();
}


if(IBAN!="")
{

if (IBAN.length !=23) {
app.alert("IBAN Validation Error!! IBAN should contain 23 Characters");
this.getField("txtIBAN").setFocus();
exit();
}
else {

var moveLast = IBAN.substring(0,2);


var CheckDigit = IBAN.substring(2, 4);

var BankCode = IBAN.substring(4, 7);
var AccountCode = IBAN.substring(7, 23);


if (CheckAllCaps(IBAN) == false) {
app.alert("Invalid IBAN");
this.getField("txtIBAN").setFocus();
exit();
}
var CountryCodeString = '';
CountryCodeString = GetCharCode(CountryCode);

app.alert(CountryCodeString);

moveLast = BankCode + AccountCode + CountryCodeString + CheckDigit;

// moveLast = RemoveLeadingZeros(moveLast);



app.alert(strcode);

var strcode = parseFloat(strcode) % 97;
app.alert(strcode);

if (strcode != "1") {
app.alert("Not a valid IBAN");
this.getField("txtIBAN").setFocus();
exit();
}
}
}

function CheckAllCaps(IBAN) {
var i = 0;
var countUpper = 0;
var countAlphabets = 0;
var character = '';
while (i <= IBAN.length) {
character = IBAN.charAt(i);
if (isNaN(character * 1)) {
countAlphabets++;
if (character == character.toUpperCase()) {
countUpper++;
}
}
i++;
}
if ((countAlphabets == 0) || (countAlphabets != countUpper)) {
return false;
}
return true;
}

function GetCharCode(CountryCode) {
var count = 0;
var CountryCodeSplit = '';
var CountryCodeStr = '';
var Result = '';
var charCodeAr = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
var DecValueAr = new Array("10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35");
while (count <= 1) {
for (var i = 0; i < charCodeAr.length; i++) {
if (CountryCode.substring(count, count + 1) == charCodeAr[i]) {
Result = Result + DecValueAr[i];
}
}
count++;
}

return Result;

}

function RemoveLeadingZeros(strDigit) {

var remain = strDigit.replace(/^0+/, '');
return remain;
}



</script>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900