MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / indian_phone_validator

Function indian_phone_validator

strings/indian_phone_validator.py:4–25  ·  view source on GitHub ↗

Determine whether the string is a valid phone number or not :param phone: :return: Boolean >>> indian_phone_validator("+91123456789") False >>> indian_phone_validator("+919876543210") True >>> indian_phone_validator("01234567896") False >>> indian_phone_valid

(phone: str)

Source from the content-addressed store, hash-verified

2
3
4def indian_phone_validator(phone: str) -> bool:
5 """
6 Determine whether the string is a valid phone number or not
7 :param phone:
8 :return: Boolean
9 >>> indian_phone_validator("+91123456789")
10 False
11 >>> indian_phone_validator("+919876543210")
12 True
13 >>> indian_phone_validator("01234567896")
14 False
15 >>> indian_phone_validator("919876543218")
16 True
17 >>> indian_phone_validator("+91-1234567899")
18 False
19 >>> indian_phone_validator("+91-9876543218")
20 True
21 """
22 pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$")
23 if match := re.search(pat, phone):
24 return match.string == phone
25 return False
26
27
28if __name__ == "__main__":

Callers 1

Calls 1

searchMethod · 0.45

Tested by

no test coverage detected