def is_valid_number_for_region(numobj, region_code):
 country_code = numobj.country_code
 if (region_code is None):
  return False
 metadata = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_code.upper())
 if ((metadata is None) or ((region_code != REGION_CODE_FOR_NON_GEO_ENTITY) and (country_code != country_code_for_valid_region(region_code)))):
  return False
 nsn = national_significant_number(numobj)
 return (_number_type_helper(nsn, metadata) != PhoneNumberType.UNKNOWN)

def is_valid_number_for_region ( numobj , region_code ) : country_code = numobj . country_code if ( region_code is None ) : return False metadata = PhoneMetadata . metadata_for_region_or_calling_code ( country_code , region_code . upper ( ) ) if ( ( metadata is None ) or ( ( region_code != REGION_CODE_FOR_NON_GEO_ENTITY ) and ( country_code != country_code_for_valid_region ( region_code ) ) ) ) : return False nsn = national_significant_number ( numobj ) return ( _number_type_helper ( nsn , metadata ) != PhoneNumberType . UNKNOWN )
tests whether a phone number is valid for a certain region .