• Resolved pexel

    (@pexel)


    hello I am trying to write an IBAN validation form. The code below is working correctly.

    The problem is to delete spaces defined in fieldname27. For some reason the js function does not work.. but it works in html.

        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.";
          }
        }

    But after I check the result, I want to print it like this.

        jQuery('#calculation-result').html(result);
        jQuery('.kriter1-aciklama').html('Sonu? :');
        jQuery('.kriter1-sonuc').html(result);

    I wonder how can I run this query correctly?
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    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 1 year, 4 months ago by pexel.
    Plugin Author codepeople

    (@codepeople)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘IBAN verification code’ is closed to new replies.