python 正则匹配手机号

Posted wenjiangtao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 正则匹配手机号相关的知识,希望对你有一定的参考价值。

import re
phone = str(input(‘请输入手机号:‘))
# b = str(12345678912)
t = re.compile(r‘^1(3d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8[0-9]|9[0-9])d{8}$‘)
s = re.search(t,phone)
# print(s)
if s:
print(s.group(),‘是正常手机号‘)
else:
print(‘手机号格式不正确‘)

技术图片

 

以上是关于python 正则匹配手机号的主要内容,如果未能解决你的问题,请参考以下文章

python 正则表达式

python常用正则表达式

Python高级详解 正则表达式(re模块)

Python高级详解 正则表达式(re模块)

python 正则匹配^和$使用问题

php正则 匹配 手机、座机号码