Reputation: 46340
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
Upvotes: 3
Views: 8921
Reputation: 12012
Regex does pattern matching, not really parsing. You need to parse the number to get the digits. I would suggest using the regex to ensure it is a 10 digit number and then ToString() it and chop it up.
Upvotes: 0
Reputation: 1500065
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.
Upvotes: 5