mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Srilankan phone number validation (#7706)
* Add is_srilankan_phone_number.py * Update is_srilankan_phone_number.py
This commit is contained in:
parent
6e809a25e3
commit
327c38d6f0
35
strings/is_srilankan_phone_number.py
Normal file
35
strings/is_srilankan_phone_number.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def is_sri_lankan_phone_number(phone: str) -> bool:
|
||||||
|
"""
|
||||||
|
Determine whether the string is a valid sri lankan mobile phone number or not
|
||||||
|
References: https://aye.sh/blog/sri-lankan-phone-number-regex
|
||||||
|
|
||||||
|
>>> is_sri_lankan_phone_number("+94773283048")
|
||||||
|
True
|
||||||
|
>>> is_sri_lankan_phone_number("+9477-3283048")
|
||||||
|
True
|
||||||
|
>>> is_sri_lankan_phone_number("0718382399")
|
||||||
|
True
|
||||||
|
>>> is_sri_lankan_phone_number("0094702343221")
|
||||||
|
True
|
||||||
|
>>> is_sri_lankan_phone_number("075 3201568")
|
||||||
|
True
|
||||||
|
>>> is_sri_lankan_phone_number("07779209245")
|
||||||
|
False
|
||||||
|
>>> is_sri_lankan_phone_number("0957651234")
|
||||||
|
False
|
||||||
|
"""
|
||||||
|
|
||||||
|
pattern = re.compile(
|
||||||
|
r"^(?:0|94|\+94|0{2}94)" r"7(0|1|2|4|5|6|7|8)" r"(-| |)" r"\d{7}$"
|
||||||
|
)
|
||||||
|
|
||||||
|
return bool(re.search(pattern, phone))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
phone = "0094702343221"
|
||||||
|
|
||||||
|
print(is_sri_lankan_phone_number(phone))
|
Loading…
Reference in New Issue
Block a user