import re
def check_phone_right(self, phone_number):
"""检测号码是否正确""" phone_number_strip = phone_number.strip() pattern = re.compile(r'^(13[0-9]|14[0|5|6|7|9]|15[0|1|2|3|5|6|7|8|9]|' r'16[2|5|6|7]|17[0|1|2|3|5|6|7|8]|18[0-9]|' r'19[1|3|5|6|7|8|9])\d{8}$') if pattern.search(phone_number_strip): pass else: raise UserError('电话号码格式不正确')
标签:验证,pattern,手机号码,number,phone,strip,python3 From: https://www.cnblogs.com/1314520xh/p/17259541.html