From 07ca983a6eeb9477d2772fdcd93848ecc2ffa60a Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Sun, 18 Jul 2021 11:52:04 +0530 Subject: [PATCH 1/6] add phone_validator method --- strings/phone_validator.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 strings/phone_validator.py diff --git a/strings/phone_validator.py b/strings/phone_validator.py new file mode 100644 index 000000000000..b94358a1ee83 --- /dev/null +++ b/strings/phone_validator.py @@ -0,0 +1,30 @@ +import re +def phone_validator(phone: str) -> bool: + """ + Determine whether the string is a valid phone number or not + :param phone: + :return: Boolean + >>> phone_validator("+91123456789") + False + >>> phone_validator("+919876543210") + True + >>> phone_validator("01234567896") + False + >>> phone_validator("919876543218") + True + >>> phone_validator("+91-1234567899") + False + """ + # Created a regex pattern to produce a valid phone number + pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$") + # Find their matches + match = re.search(pat, phone) + # if match are present + if match: + # the match is the same as the phone string it means they are valid phone number. + return match.string == phone + # if match are none so return False. + return False + +if __name__ == "__main__": + print(phone_validator('+91123456789')) \ No newline at end of file From dd25a7efe656582eab9254fc62ee2a0940f416a8 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Mon, 19 Jul 2021 20:52:04 +0530 Subject: [PATCH 2/6] change the phone_validator to indian_phone_validator --- ..._validator.py => indian_phone_validator.py} | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) rename strings/{phone_validator.py => indian_phone_validator.py} (50%) diff --git a/strings/phone_validator.py b/strings/indian_phone_validator.py similarity index 50% rename from strings/phone_validator.py rename to strings/indian_phone_validator.py index b94358a1ee83..0143b32d1f7f 100644 --- a/strings/phone_validator.py +++ b/strings/indian_phone_validator.py @@ -1,30 +1,28 @@ import re -def phone_validator(phone: str) -> bool: +def indian_phone_validator(phone: str) -> bool: """ Determine whether the string is a valid phone number or not :param phone: :return: Boolean - >>> phone_validator("+91123456789") + >>> indian_phone_validator("+91123456789") False - >>> phone_validator("+919876543210") + >>> indian_phone_validator("+919876543210") True - >>> phone_validator("01234567896") + >>> indian_phone_validator("01234567896") False - >>> phone_validator("919876543218") + >>> indian_phone_validator("919876543218") True - >>> phone_validator("+91-1234567899") + >>> indian_phone_validator("+91-1234567899") False """ # Created a regex pattern to produce a valid phone number pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$") # Find their matches match = re.search(pat, phone) - # if match are present + # if the match is present to check for the phone string is valid or not. if match: - # the match is the same as the phone string it means they are valid phone number. return match.string == phone - # if match are none so return False. return False if __name__ == "__main__": - print(phone_validator('+91123456789')) \ No newline at end of file + print(indian_phone_validator('+918827897895')) \ No newline at end of file From ccddd09521eeb8d83e7fa645f1498a435570d743 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Mon, 19 Jul 2021 21:34:39 +0530 Subject: [PATCH 3/6] Unnecessary comments removed --- strings/indian_phone_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/indian_phone_validator.py b/strings/indian_phone_validator.py index 0143b32d1f7f..5d7c22f5973a 100644 --- a/strings/indian_phone_validator.py +++ b/strings/indian_phone_validator.py @@ -17,7 +17,7 @@ def indian_phone_validator(phone: str) -> bool: """ # Created a regex pattern to produce a valid phone number pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$") - # Find their matches + # Find matches match = re.search(pat, phone) # if the match is present to check for the phone string is valid or not. if match: From 7cad82fcc6db30fac5b8b9c84e3daae8bc79130e Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Tue, 20 Jul 2021 03:55:35 +0530 Subject: [PATCH 4/6] all comments deleted --- strings/indian_phone_validator.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/strings/indian_phone_validator.py b/strings/indian_phone_validator.py index 5d7c22f5973a..5160be2708ad 100644 --- a/strings/indian_phone_validator.py +++ b/strings/indian_phone_validator.py @@ -15,14 +15,12 @@ def indian_phone_validator(phone: str) -> bool: >>> indian_phone_validator("+91-1234567899") False """ - # Created a regex pattern to produce a valid phone number pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$") - # Find matches match = re.search(pat, phone) - # if the match is present to check for the phone string is valid or not. if match: return match.string == phone return False + if __name__ == "__main__": - print(indian_phone_validator('+918827897895')) \ No newline at end of file + print(f'{indian_phone_validator("+918827897895")}\n') \ No newline at end of file From 6bd830bb1cba9353049d38cce2fe639b1c4d6abf Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Tue, 20 Jul 2021 11:00:00 +0530 Subject: [PATCH 5/6] Fixes: #{} new line issue --- strings/indian_phone_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/indian_phone_validator.py b/strings/indian_phone_validator.py index 5160be2708ad..6be20c5f294f 100644 --- a/strings/indian_phone_validator.py +++ b/strings/indian_phone_validator.py @@ -23,4 +23,4 @@ def indian_phone_validator(phone: str) -> bool: if __name__ == "__main__": - print(f'{indian_phone_validator("+918827897895")}\n') \ No newline at end of file + print(indian_phone_validator("+918827897895")) From dc1ef1095e31966a5f45d8acc701c91ecb54e435 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Tue, 20 Jul 2021 12:58:57 +0530 Subject: [PATCH 6/6] code reformatted using black --- strings/indian_phone_validator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/indian_phone_validator.py b/strings/indian_phone_validator.py index 6be20c5f294f..d544e92661b1 100644 --- a/strings/indian_phone_validator.py +++ b/strings/indian_phone_validator.py @@ -1,4 +1,6 @@ import re + + def indian_phone_validator(phone: str) -> bool: """ Determine whether the string is a valid phone number or not