You are here:

Validate an IBAN

forget isdigit?

 

// countrycode checksum bankcode sortcode accountnumber

 

: isdigit?   ( char -- boolean )

  dup '0' >=

  swap '9' <= and

;

  

: stripspaces   ( IBAN -- IBAN' )

   "" 2swap split for

    forobj concat$

  each

;

 

: valid?   ( IBAN -- boolean )

  string NUM$

  0 char-array IBAN

  stripspaces

  >carr a@ IBAN a!

  4 0 do

    IBAN 0 <@

    IBAN |<!

  loop

  IBAN a@ 0 do

    dup isdigit? not if

      asc 55 -

    then

    NUM$ swap str$ s<& drop

  loop

  NUM$ @

 

  97 mod

  1 ==

;

 

"GB26 MIDL 4005 1512 3456 74" valid? . cr


ok> true

ok>

Validate an IBAN: