ifconfig
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\'))

  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2021-12-23
  • 2021-11-11
  • 2021-11-11
  • 2018-08-30
  • 2021-11-05
猜你喜欢
  • 2021-10-18
  • 2022-12-23
  • 2021-11-11
  • 2022-01-05
  • 2021-12-30
  • 2021-09-12
  • 2022-01-02
相关资源
相似解决方案