# NHS Number Validation (Modulus 11)

Here’s a snippet of code that I would have found useful about 30 minutes
ago.

I needed to allow users to enter a United Kingdom NHS Number.
This is a 10 digit number (9 real, 1 check digit). It is validated using
the Modulus 11 algorithm
Details about it are here: h

Here’s the expression syntax to validate it (assuming your Question ID is
’NHS_Number’):
11 - (substr(/data/NHS_Number, 0, 1) * 10 + substr(/data/NHS_Number, 1, 2) *
9 + substr(/data/NHS_Number, 2, 3) * 8 + substr(/data/NHS_Number, 3, 4) * 7

• substr(/data/NHS_Number, 4, 5) * 6 + substr(/data/NHS_Number, 5, 6) * 5 +
substr(/data/NHS_Number, 6, 7) * 4 + substr(/data/NHS_Number, 7, 8) * 3 +
substr(/data/NHS_Number, 8, 9) * 2) mod 11 = substr(/data/NHS_Number, 9, 10)

Hope it helps someone,

Ben

great that you are sharing your code!

nothing like a nice big tangle of string processing functions… when it
all works out you feel you have really created a great beast.

Actually, quite similar – if anyone ever wants to talk about the methods
you need to take to assemble good UIC codes from a handful of questions
asked of a given client… like “what province were you born in… what’s
the first letter of your first name…” … I’m happy to share our
experiences too. When you are dealing with non-latin alphabets like Lao and
Thai, and using lookup tables to allow you to pick alphabet letters, it
gets to be pretty fancy after a while.

Hi Eric,

Is there a way to validate South African ID numbers in a similar way? Or
would I need a database to verify this against?

Kindly,
Ameera

··· On Friday, 12 February 2016 07:18:14 UTC+2, Eric Stephan wrote: > > Actually, quite similar -- if anyone ever wants to talk about the methods > you need to take to assemble good UIC codes from a handful of questions > asked of a given client... like "what province were you born in... what's > the first letter of your first name..." ... I'm happy to share our > experiences too. When you are dealing with non-latin alphabets like Lao and > Thai, and using lookup tables to allow you to pick alphabet letters, it > gets to be pretty fancy after a while. >

It appears that South Africa use the Modulus 10/Luhn Algorithm to validate.

While my code above won’t help you I’m sure you could re-write it to fit
the Luhn algorithm rules.

··· On Monday, 15 February 2016 10:35:10 UTC, Ameera Hamid wrote: > > Hi Eric, > > Is there a way to validate South African ID numbers in a similar way? Or > would I need a database to verify this against? > > Kindly, > Ameera > > On Friday, 12 February 2016 07:18:14 UTC+2, Eric Stephan wrote: >> >> Actually, quite similar -- if anyone ever wants to talk about the methods >> you need to take to assemble good UIC codes from a handful of questions >> asked of a given client... like "what province were you born in... what's >> the first letter of your first name..." ... I'm happy to share our >> experiences too. When you are dealing with non-latin alphabets like Lao and >> Thai, and using lookup tables to allow you to pick alphabet letters, it >> gets to be pretty fancy after a while. >> >