
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