Reputation: 2764
I'm using Google's libphonenumber library in order to validate mobile numbers, but I want to just accept mobile numbers and refuse fixed-line numbers.
Is this possible?
Here is my phone number validation code:
public bool MobileNumberContentValidator(string mobileNumber, string region)
{
var phoneUtil = PhoneNumberUtil.GetInstance();
var phone = phoneUtil.Parse(mobileNumber, region.ToUpper());
if (phoneUtil.IsValidNumber(phone))//its validate all kind of phone numbers
return true;
else
return false;
}
This method validates both fixed-line and mobile numbers. I want to reject fixed-line numbers and accept mobile numbers.
Upvotes: -6
Views: 2823
Reputation: 2764
Finally I found this in order to accept just mobile numbers:
if (phoneUtil.GetNumberType(mobile) == PhoneNumberType.MOBILE) return true
Upvotes: 5