On-the-fly bank account numbers verification
Asked Answered
E

1

6

Today I had to copy a bank account number from a real (dead tree) letter to an Emacs buffer and then send it by email. And I made a mistake while copying it from the letter to the Emacs buffer (forgot one digit). Which resulted in one email from a coworker telling me: "couldn't make the payment, bogus IBAN".

How hard would it be to create a function/minor-mode that would:

  • detect "things" that do look like an IBAN (for example two uppercase letters followed by between 'x' and 'y' digits, ignoring spaces etc. There are ready-to-use regexps out there that verify if something looks like an IBAN or not)

  • run a mod 97 and highlight the IBAN in red if it looks invalid

Ideally I'd need a minor-mode that I could turn on for several types of buffers (silly text files, but also email, etc.).

What would be the "approach" to use to do that using Emacs?

Echinate answered 9/5, 2012 at 16:58 Comment(3)
This is not an answerable question, unless you'd accept it if someone said "Not too hard", or "Very hard". Please edit to ask a specific question, instead of a generic "how hard would it be?". Thanks. :)Wafer
Maybe answer the question he wanted to ask, instead of the question he actually asked. There's some risk to making the assumption required to do that, but in this case I'd say it's warranted.Gavan
I remember writing a function in response to this but I never seem to have posted an answer. If there is interest in it, please ping me and I'll see if I can dig it up.Turbinate
B
9

You can easily use something like

(font-lock-add-keywords nil
  '(("[A-Z][A-Z][0-9]\\{x,y\\}"
     (0 (if (eq (mod blabla 97) foo) nil 'font-lock-warning-face))))))

Just fill in the blabla.

Brandonbrandt answered 10/5, 2012 at 2:18 Comment(1)
Emacs never ceases to amaze me :)Echinate

© 2022 - 2024 — McMap. All rights reserved.