Created
May 26, 2015 05:18
-
-
Save sincerefly/50470430e4755ceff489 to your computer and use it in GitHub Desktop.
使用正则表达式判断电话号码格式正确与否
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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