python 判断手机号码和正整数

import re

'''
输入手机号码,判断手机号码是否为11位,是否为1开头的数值
'''
def get_phone():
    while True:
        phone = input('请输入手机号码:')
        if len(phone) == 11 and re.match(r'1\d{10}', phone):
            return phone
        else:
            print('请输入11位的手机号')

'''
输入数量,判断数量是否为正整数
'''
def get_amount():
    while True:
        amount = input('请输入数量:')
        if amount.isdigit() and int(amount) >= 0:
            return amount
        else:
            print('请输入正整数!')

猜你喜欢

转载自blog.csdn.net/happyuu/article/details/82772869