Skip to content

Commit

Permalink
Merge pull request #8 from heetch/BCN-3536-support-new-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharykhin authored Oct 24, 2024
2 parents 4129f86 + 34e3cad commit 0de486c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion phonenumberutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ var (
FIRST_GROUP_ONLY_PREFIX_PATTERN = regexp.MustCompile("\\(?\\$1\\)?")

REGION_CODE_FOR_NON_GEO_ENTITY = "001"

MaliNationalPhoneRegExp = regexp.MustCompile("^(?:2(?:0(?:01|79)|17\\d)\\d{4}|(?:5[01]|[6789]\\d|8[2-49])\\d{6})$")
)

// INTERNATIONAL and NATIONAL formats are consistent with the definition
Expand Down Expand Up @@ -2159,7 +2161,19 @@ func isNumberMatchingDesc(nationalNumber string, numberDesc *PhoneNumberDesc) bo
// just looking at a number itself.
func IsValidNumber(number *PhoneNumber) bool {
var regionCode string = GetRegionCodeForNumber(number)
return IsValidNumberForRegion(number, regionCode)
isValid := IsValidNumberForRegion(number, regionCode)
// Mali raised new phone number prefix 85 which is still not supported by the latest version
// of libphonenumber. So we need to validate it manually.
if regionCode == "ML" {
return validateNewMaliPrefix(number)
}

return isValid
}

func validateNewMaliPrefix(number *PhoneNumber) bool {
var nationalSignificantNumber = GetNationalSignificantNumber(number)
return MaliNationalPhoneRegExp.Match([]byte(nationalSignificantNumber))
}

// Tests whether a phone number is valid for a certain region. Note this
Expand Down
5 changes: 5 additions & 0 deletions phonenumberutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func Test_IsValidNumber(t *testing.T) {
err: nil,
isValid: true,
region: "US",
}, {
input: "+22385050597",
err: nil,
isValid: true,
region: "ML",
}, {
input: "+244972577111",
err: nil,
Expand Down

0 comments on commit 0de486c

Please sign in to comment.