laravel-mtn-momo icon indicating copy to clipboard operation
laravel-mtn-momo copied to clipboard

Valid MSISDN

Open mtvbrianking opened this issue 3 years ago • 2 comments

function msisdn($phoneNumber, $countryCode = '256', $networkCodes = '39|76|77|78')
{
    $phoneNumber = preg_replace('/[^\d]/', '', $phoneNumber);

    if(! preg_match("/^(0|{$countryCode})({$networkCodes})[\d+]{7}$/", $phoneNumber, $matches)) {
        throw new \InvalidArgumentException('Invalid phone number');
    }

    if($matches[1] == '0') {
        $phoneNumber = substr_replace($phoneNumber, $countryCode, 0, 1);
    }

    return $phoneNumber;
}

echo msisdn('0788123456'); // 256788123456 - OK
echo msisdn('0700123456'); // Invalid phone number
echo msisdn('256788123456'); // 256788123456 - OK
echo msisdn('+256788123456'); // 256788123456 - OK
echo msisdn('+256 (788) 123456'); // 256788123456 - OK
echo msisdn('+46 (788) 123456'); // Invalid phone number

mtvbrianking avatar Feb 06 '22 10:02 mtvbrianking

what is the issue here ?

stevebaros avatar Feb 07 '22 09:02 stevebaros

No apparent issue.

I just documented it as a desirable improvement for the next version borrowing from another momo plugin I worked on recently.

mtvbrianking avatar Feb 07 '22 16:02 mtvbrianking