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>

Why to use 7th


  • 7ᵗʰ comes in a tiny package of only about 0.5 Mb containing the whole IDE
  • 7ᵗʰ needs no installation – only a download of one jar-file to start
  • 7ᵗʰ contains an integrated help
  • 7ᵗʰ is fully integratable in existing or new Java programs
  • 7ᵗʰ implements the ScriptEngine pattern
  • 7ᵗʰ runs on every computer with an installed JVM
  • 7ᵗʰ can run headless as a console application
  • 7ᵗʰ programs / words are very compact



here You can download the source-code of the example on the left:

Validate an IBAN: