我正在使用 Google 的 libphonenumber 库来验证电话号码,但我只想接受手机号码并拒绝固定电话号码。
这可能吗?
这是我的电话号码验证码:
Result PhoneContentValidator(string phoneNumber, string region)
{
Result result;
PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();
PhoneNumber phone = phoneUtil.Parse(phoneNumber, region.ToUpper());
try
{
if (phoneUtil.IsValidNumber(phone) != true) return result = new Result { resultIsValid = true, resultText = "Not Valid Mobile Number", result = false };
else return result = new Result { resultIsValid = true, resultText = Main_Log.ApplicationSuccessMessage, result = true };
}
catch (Exception ex)
{
Main_Log.GetLogger().Error(Main_Log.MessageForLogFile("phone content validation failed due to the exception in application. ", ex.Message, ex.HResult));
return result = new Result { resultIsValid = false, resultText = ex.Message };
}
}
此方法同时验证固定电话号码和移动电话号码。我想拒绝固定电话号码并接受手机号码。