Mobile phone-number validation

Hi everyone, I'm trying to create some code to validate/sanitize mobile phone numbers entered by users, for use with SMS gateways. So far I have the following: 729974802 becomes: 254729974802 0729974802 becomes: 254729974802 0 729 974 802 becomes: 254729974802 254 729974802 becomes: 254729974802 +254 729974802 becomes: 254729974802 (254) 7 29974802 becomes: 254729974802 +(254) 7 29974802 becomes: 254729974802 (+254) (0) 7 29974802 becomes: 254729974802 However I am not sure that I have captured all the different ways that a Kenyan mobile-phone number could be entered. So the question to you all is: are there more ways a number could be entered ? n.b. if anyone is interested the code for the above is (in php): $phone = '254' . preg_replace('/^\+?(\(?\+?254\)?)?(\(?0\)?)?7/', '7', str_replace(' ', '', $input)); .. Mike

CCK have regitsered all the number prefix used in Kenya. Check on their site. On Sun, Jul 24, 2011 at 10:10 PM, Michael Pedersen <sku@kaal.dk> wrote:
Hi everyone,
I'm trying to create some code to validate/sanitize mobile phone numbers entered by users, for use with SMS gateways.
So far I have the following:
729974802 becomes: 254729974802 0729974802 becomes: 254729974802 0 729 974 802 becomes: 254729974802 254 729974802 becomes: 254729974802 +254 729974802 becomes: 254729974802 (254) 7 29974802 becomes: 254729974802 +(254) 7 29974802 becomes: 254729974802 (+254) (0) 7 29974802 becomes: 254729974802
However I am not sure that I have captured all the different ways that a Kenyan mobile-phone number could be entered. So the question to you all is: are there more ways a number could be entered ?
n.b. if anyone is interested the code for the above is (in php): $phone = '254' . preg_replace('/^\+?(\(?\+?254\**)?)?(\(?0\)?)?7/', '7', str_replace(' ', '', $input));
.. Mike
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------ Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke
-- Jackson Gathoni

Hi Jack (and everyone else). Thank you for that hint. I went to CCK and found the PDF of the numbering plan for Kenya - I assume this is the resource you are referring to. I find mobile numbering at page 27, but can not identify anything there that would tell me how numbers would be listed in any other way than what I previously listed. Maybe I am missing something (?) Could you please clarify what exactly it is you feel I am missing in the numbering plan - that would be very helpful - thanks. Oh on second thought... are you referring to the fact that no numbers are assigned within the following number-series ? [703-709] [740-749] [754-769] [775-785] [790-799] .. Mike On 7/24/11 10:29 PM, Jac wrote:
CCK have regitsered all the number prefix used in Kenya. Check on their site.
On Sun, Jul 24, 2011 at 10:10 PM, Michael Pedersen <sku@kaal.dk <mailto:sku@kaal.dk>> wrote:
Hi everyone,
I'm trying to create some code to validate/sanitize mobile phone numbers entered by users, for use with SMS gateways.
So far I have the following:
729974802 becomes: 254729974802 0729974802 becomes: 254729974802 0 729 974 802 becomes: 254729974802 254 729974802 becomes: 254729974802 +254 729974802 <tel:%2B254%20729974802> becomes: 254729974802 (254) 7 29974802 becomes: 254729974802 +(254) 7 29974802 <tel:%2B%28254%29%207%2029974802> becomes: 254729974802 (+254) (0) 7 29974802 <tel:%28%2B254%29%20%280%29%207%2029974802> becomes: 254729974802
However I am not sure that I have captured all the different ways that a Kenyan mobile-phone number could be entered. So the question to you all is: are there more ways a number could be entered ?
n.b. if anyone is interested the code for the above is (in php): $phone = '254' . preg_replace('/^\+?(\(?\+?254\)?)?(\(?0\)?)?7/', '7', str_replace(' ', '', $input));
.. Mike
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke <mailto:Skunkworks@lists.my.co.ke> http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 <http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke
-- Jackson Gathoni
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Hi, what of +2540729974802 2540729974802 0729-974-802 0729 974 802 254 0729 974 802 +254 729 974 802 I may have repeated some yours - but looking at your code, am sure it would capture these too.. :) -Alex On Sun, Jul 24, 2011 at 10:10 PM, Michael Pedersen <sku@kaal.dk> wrote:
Hi everyone,
I'm trying to create some code to validate/sanitize mobile phone numbers entered by users, for use with SMS gateways.
So far I have the following:
729974802 becomes: 254729974802 0729974802 becomes: 254729974802 0 729 974 802 becomes: 254729974802 254 729974802 becomes: 254729974802 +254 729974802 becomes: 254729974802 (254) 7 29974802 becomes: 254729974802 +(254) 7 29974802 becomes: 254729974802 (+254) (0) 7 29974802 becomes: 254729974802
However I am not sure that I have captured all the different ways that a Kenyan mobile-phone number could be entered. So the question to you all is: are there more ways a number could be entered ?
n.b. if anyone is interested the code for the above is (in php): $phone = '254' . preg_replace('/^\+?(\(?\+?254\**)?)?(\(?0\)?)?7/', '7', str_replace(' ', '', $input));
.. Mike
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------ Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke

Personally I am a student of Occam's razor. A mobile number (in Kenya at any rate) Is composed of 9 digits (barring the zero and/or country code) So a regex that removes all non digits from a given number and then captures 9 digits from the end of line should work consistently. You can then add the leading 0 or the country prefix in code On Sun, Jul 24, 2011 at 11:06 PM, Alex Wanjohi <wanjohialex@gmail.com>wrote:
Hi,
what of +2540729974802 2540729974802 0729-974-802 0729 974 802 254 0729 974 802 +254 729 974 802
I may have repeated some yours - but looking at your code, am sure it would capture these too.. :)
-Alex
On Sun, Jul 24, 2011 at 10:10 PM, Michael Pedersen <sku@kaal.dk> wrote:
Hi everyone,
I'm trying to create some code to validate/sanitize mobile phone numbers entered by users, for use with SMS gateways.
So far I have the following:
729974802 becomes: 254729974802 0729974802 becomes: 254729974802 0 729 974 802 becomes: 254729974802 254 729974802 becomes: 254729974802 +254 729974802 becomes: 254729974802 (254) 7 29974802 becomes: 254729974802 +(254) 7 29974802 becomes: 254729974802 (+254) (0) 7 29974802 becomes: 254729974802
However I am not sure that I have captured all the different ways that a Kenyan mobile-phone number could be entered. So the question to you all is: are there more ways a number could be entered ?
n.b. if anyone is interested the code for the above is (in php): $phone = '254' . preg_replace('/^\+?(\(?\+?254\**)?)?(\(?0\)?)?7/', '7', str_replace(' ', '', $input));
.. Mike
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------ Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

AH - yes of course.. Sometimes the most simple solutions are just too obvious to be seen - Thanks (maybe its time to stop coding for the day - clearly my mind is not sharp) code: $phone = '254' . substr(preg_replace('/[^0-9]*/', '', $input), -9); .. Mike On 7/24/11 11:13 PM, Rad! wrote:
Personally I am a student of Occam's razor.
A mobile number (in Kenya at any rate) Is composed of 9 digits (barring the zero and/or country code)
So a regex that removes all non digits from a given number and then captures 9 digits from the end of line should work consistently.
You can then add the leading 0 or the country prefix in code
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

This might probably not solve your problem, but if the users were entering those numbers via an interface you have control over, e.g. a webform, then you could force them to enter the number in your predefined way, e.g. a dropdown with the prefixes etc On Sun, Jul 24, 2011 at 11:22 PM, Michael Pedersen <sku@kaal.dk> wrote:
AH - yes of course..
Sometimes the most simple solutions are just too obvious to be seen - Thanks (maybe its time to stop coding for the day - clearly my mind is not sharp)
code: $phone = '254' . substr(preg_replace('/[^0-9]*/**', '', $input), -9);
.. Mike
On 7/24/11 11:13 PM, Rad! wrote:
Personally I am a student of Occam's razor.
A mobile number (in Kenya at any rate) Is composed of 9 digits (barring the zero and/or country code)
So a regex that removes all non digits from a given number and then captures 9 digits from the end of line should work consistently.
You can then add the leading 0 or the country prefix in code
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------ Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke
______________________________**_________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/**mailman/listinfo/skunkworks<http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks> ------------ Skunkworks Rules http://my.co.ke/phpbb/**viewtopic.php?f=24&t=94<http://my.co.ke/phpbb/viewtopic.php?f=24&t=94> ------------ Other services @ http://my.co.ke
-- Regards, Peter Karunyu ------------------- Web Performance Evangelist *Make your website and web app faster.*

Hi Alex, Thank you for that input. For good measurement I ran them all though the code - most of them are covered, but the "0729-974-802" was not - so great that we caught that one. I added it to the code: $phone = '254' . preg_replace('/^\+?(\(?\+?254\)?)?(\(?0\)?)?7/', '7', str_replace(array(' ', '-'), '', $input)); .. Mike On 7/24/11 11:06 PM, Alex Wanjohi wrote:
Hi,
what of +2540729974802 2540729974802 0729-974-802 0729 974 802 254 0729 974 802 +254 729 974 802
I may have repeated some yours - but looking at your code, am sure it would capture these too.. :)
-Alex
participants (5)
-
Alex Wanjohi
-
Jac
-
Michael Pedersen
-
Peter Karunyu
-
Rad!