mod 11 check digit with regex

Jeremy picture Jeremy · Jun 3, 2009 · Viewed 7.5k times · Source

Is it possible to create a mod 11 check digit routine with a regex statement?

THe nubmer is a 10 digit number,

Step 1: A = (2nd number * 2) + (3rd number * 4) + (4th number * 8) + (5th number * 5) + (6th number * 10) + (7th number * 9) + (8th number * 7) + (9th number * 3))

Step 2: B = A / 11 (ignor remainder)

Step 3: C = B * 11

Step 4: D = A - C

Step 5: 11 - D must = the 10th digit

Answer

Jon Skeet picture Jon Skeet · Jun 3, 2009

No - fundamentally you're wanting to do maths here, and that doesn't really fit with regular expressions which are just about patterns.

I mean, theoretically it's certainly possible - you could list all valid numbers, and combine them into one enormous regex. However, it's not practically feasible.