Skip to content

Instantly share code, notes, and snippets.

@sincerefly
Created May 26, 2015 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sincerefly/50470430e4755ceff489 to your computer and use it in GitHub Desktop.
Save sincerefly/50470430e4755ceff489 to your computer and use it in GitHub Desktop.
使用正则表达式判断电话号码格式正确与否
import re
def validPhoneNumber(phoneNumber):
return bool(re.match(r"^(\([0-9]+\))? [0-9]+-[0-9]+$", phoneNumber))
# 使用正则表达式判断电话号码格式正确与否
#validPhoneNumber("(123) 456-7890") => returns true
#validPhoneNumber("(1111)555 2345") => returns false
#validPhoneNumber("(098) 123 4567") => returns false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment