Hello @pexel
If you entered the code as part of an equation, the line of code:
var iban = document.getElementById("fieldname27").value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
Need to be edited as follows
var iban = String(fieldname27|r).replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
If the code was entered as an auxiliary operation via “HTML Content” field:
var iban = String(getField("fieldname27").val(true, true)).replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
If you need a custom coding service to implement a IBAN validator on your form, do not hesitate to contact us via plugin website:
https://cff.dwbooster.com/contact-us
Best regards.
Thread Starter
pexel
(@pexel)
This way the code structure works but fieldname27; If I define it like this, it writes the result. It doesn’t delete the spaces in between. I tried as you gave. Not working.
For example: TR80 0006 2000 0670 0006 6844 77 iban is valid but it says invalid. Actually my method is correct but the problem persists because of fieldname27 field.
(function() {
var iban = fieldname27;
var ibanPattern = /^[A-Z]{2}\d{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}$/;
if (ibanPattern.test(iban)) {
var numericIBAN = iban.substring(4) + iban.substring(0, 4);
var numericIBANBigInt = BigInt(numericIBAN);
var modValue = numericIBANBigInt % 97n;
var isValid = modValue === 1n || (modValue === 0n && iban.substring(2, 4) === '00');
var ibanStatus = isValid ? 'Geçerli' : 'Geçersiz';
jQuery('#calculation-iban').html(iban);
jQuery('.kriter1-aciklama').html('IBAN:');
jQuery('.kriter1-sonuc').html(ibanStatus);
return [ibanStatus];
} else {
var ibanStatus = 'Geçersiz IBAN';
jQuery('#calculation-iban').html(iban);
jQuery('.kriter1-aciklama').html('IBAN:');
jQuery('.kriter1-sonuc').html(ibanStatus);
return [ibanStatus];
}
})();
this is the full working code (I couldn’t adapt)
function validateIBAN() {
var iban = document.getElementById("fieldname27").value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
var ibanPattern = /^[A-Z]{2}\d{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}$/;
if (ibanPattern.test(iban)) {
var countryCode = iban.substring(0, 2);
var checkDigits = iban.substring(2, 4);
var bban = iban.substring(4);
var numericIBAN = bban + countryCode + checkDigits;
var numericValue = "";
for (var i = 0; i < numericIBAN.length; i++) {
var charValue = numericIBAN[i].toUpperCase().charCodeAt(0) - 55;
if (charValue >= 10 && charValue <= 35) {
numericValue += charValue;
} else {
numericValue += numericIBAN[i];
}
}
var mod97 = BigInt(numericValue) % 97n;
if (mod97 === 1n) {
document.getElementById("result").innerHTML = "IBAN geçerli.";
} else {
document.getElementById("result").innerHTML = "IBAN geçerli değil.";
}
} else {
document.getElementById("result").innerHTML = "Geçerli bir IBAN girin.";
}
}
-
This reply was modified 2 years, 11 months ago by
pexel.
Hello @pexel
If you check my previous code, I don’t recommended you to replace the code with: var iban = fieldname27;
Please, re-read my previous entry.
If you have any other questions, please, indicate the URL to the page that contains the form to check your code in action.
Best regards.
Hello @pexel
The “RegExp for Calculated Fields Form” complementary plugin includes an IBAN validation rule that validates the values of the fields for you:
https://cff-bundles.dwbooster.com/product/regexp
Best regards.