def isPhoneNumber(text): #固定电话 if len(text) != 13: return False # 位数不够 for i in range(0, 4): if not text[i].isdecimal(): return False # 区号不对 if text[4] != \'-\': return False # 没有分割符号 for i in range(5, 13): if not text[i].isdecimal(): return False # 检测电话号码主体是不是数字 return True # "text" is a phone number! print(\'0579-56574828 is a phone number:\') print(isPhoneNumber(\'0579-56574828\')) print(\'Moshi moshi is a phone number:\') print(isPhoneNumber(\'Moshi moshi\'))