正则表达式与python的联系

# 正则表达式不是Python独有的,它是一门独立的技术,所有的编程语言都可以使用正则
# 但要在python中使用正则表达式,就必须依赖于python内置的re 模块

验证手机号是否合法的小案例

phone_number = input('please input your phone number : ')
if len(phone_number) == 11 \
        and phone_number.isdigit() \
        and (phone_number.startswith('13') \
             or phone_number.startswith('14') \
             or phone_number.startswith('15') \
             or phone_number.startswith('18') \
             or phone_number.startswith('19')):
    print('是合法的手机号码')
else:
    print('不是合法的手机号码')
纯使用python代码版

相关文章:

  • 2021-08-23
  • 2021-12-19
  • 2021-07-30
  • 2021-11-05
  • 2021-09-04
  • 2022-01-12
  • 2021-10-21
猜你喜欢
  • 2021-06-01
  • 2021-12-18
  • 2021-12-26
  • 2021-05-14
  • 2021-08-13
  • 2021-12-09
  • 2022-01-02
相关资源
相似解决方案