Some time ago I come across need to validate electric MPAN (Meter Point Administration Number) numbers for a client in which users input the MPAN in a form and so we needed a way to make sure that nonsense numbers were not entered.

So I tried to find a ready made solution which after a long google search revealed nothing for a solution to validate these numbers in php but I did find a useful resource on Wikipedia http://en.wikipedia.org/wiki/Meter_Point_Administration_Number, but no php function was there so I set to converting the JavaScript function found there into php.

The test to verify a MPAN number is the modulus 11 test and is done on the last 13 digits, the last number being the check digit of the MPAN and goes thus:

• Multiply the first digit by 3.
• Multiply the second digit by the next prime number (5).
• Repeat this for each digit (missing 11 out on the list of prime numbers for the purposes of this algorithm.).
• Add up all these numbers.
• The check digit is the sum modulo 11 modulo 10.

So the function in php to do this is:

In a future post I will show how to make a zend framework implementation of this check using Zend_Form and Zend_Validate.

Anyway I hope this helps someone.

• Hi to every single one, it’s really a nice for me to go to see this web page, it includes important Information.

• faani

Can you please show the calculations as well. that how did it calculate modulus after multiplying it by prime numbers. Like 1800021679848 has the check digit 8. how do you calculate it to bring 8 as the answer after getting the product of each number.
3 40 0 0 0 38 23 174 217 333 328 172
Total: 1328
What’s next?

• When we use modulus were are asking for the remainer of a division so 1328 % 11 % 10 is saying divide 1328 by 11 and then divide the remainer by 10 and give the remainer of that.

The PHP operator ‘%’ does all the work for us so we don’t have to work out the modulus the long way.

To do it long hand would be:
1328 / 11 = 120.727273
120.727273 – 120 = 0.727273
0.727273 * 11 = 8 (this is our modulus 11)
8 / 10 = 0.8
0.8 * 10 = 8 (this is our modulus 10)

So the answer equals 8 and our number passes

• faani

This is really helpful.. Thanks a lot Mr. Shaun Freeman for the help..