Ummed_Singh_Shekhawat Posted August 16, 2013 Share Posted August 16, 2013 (edited) how to validate european phone number?i will got mad plz help me to sort this one Edited August 16, 2013 by Ummed_Singh_Shekhawat Quote Link to comment https://forums.phpfreaks.com/topic/281237-how-to-validate-european-phone-number/ Share on other sites More sharing options...
darkfreaks Posted August 16, 2013 Share Posted August 16, 2013 Here's a simple function for formatting phone numbers with 7 to 10 digits in a more European (or Swedish?) manner: function formatPhone($num) { $num = preg_replace('/[^0-9]/', '', $num); $len = strlen($num); if($len == 7) $num = preg_replace('/([0-9]{2})([0-9]{2})([0-9]{3})/', '$1 $2 $3', $num); elseif($len == 8) $num = preg_replace('/([0-9]{3})([0-9]{2})([0-9]{3})/', '$1 - $2 $3', $num); elseif($len == 9) $num = preg_replace('/([0-9]{3})([0-9]{2})([0-9]{2})([0-9]{2})/', '$1 - $2 $3 $4', $num); elseif($len == 10) $num = preg_replace('/([0-9]{3})([0-9]{2})([0-9]{2})([0-9]{3})/', '$1 - $2 $3 $4', $num); return $num; } Quote Link to comment https://forums.phpfreaks.com/topic/281237-how-to-validate-european-phone-number/#findComment-1445321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.