Skip to content

Commit

Permalink
Resolve NumberParseException from PhoneNumberUtil to invalid no.
Browse files Browse the repository at this point in the history
  • Loading branch information
hggutvik committed Oct 7, 2024
1 parent 44e2d49 commit 413a001
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ public static bool IsValidMobileNumber(string? mobileNumber)
}

PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance();

bool isValidNumber;

try
{
PhoneNumber phoneNumber = phoneNumberUtil.Parse(mobileNumber, null);
return phoneNumberUtil.IsValidNumber(phoneNumber);
isValidNumber = phoneNumberUtil.IsValidNumber(phoneNumber);
}
catch (NumberParseException)
{
isValidNumber = false;
}

return isValidNumber;
}
}
}

0 comments on commit 413a001

Please sign in to comment.