Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid MSISDN #68

Open
mtvbrianking opened this issue Feb 6, 2022 · 2 comments
Open

Valid MSISDN #68

mtvbrianking opened this issue Feb 6, 2022 · 2 comments

Comments

@mtvbrianking
Copy link
Owner

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
@stevebaros
Copy link
Contributor

what is the issue here ?

@mtvbrianking
Copy link
Owner Author

No apparent issue.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants