Python中手动写判断电话号码




#判断是不是电话号码
方法1


def checkPhone(str):
if len(str) !=11:
return False
elif str[0]!="1":
return False
#elif str

for i in str:
if i>="0" or i<="9":
return True

return False
print(checkPhone("13135354568"))
print(checkPhone("23135354568"))

方法2
import re
print("--------------------------")
def checkPhone2(str):
pat=r"^1(([35789]\d)|(47))\d{8}$"
res= re.match(pat,str)
print(res)

print(checkPhone2("13135354568"))
print(checkPhone2("23135354568"))
print(checkPhone2("13135b54568"))
print(checkPhone2("14735354568"))

方法3
def checkPhone3(str):
pat=r"(1(([35789]\d)|(47))\d{8})"
res= re.findall(pat,str)
print(res)
checkPhone3("dfad14735354568fewdf13135354568klmdfa")
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM