Решение на Регулярни изрази от Евгени Евлогиев

Обратно към всички решения

Към профила на Евгени Евлогиев

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 36 успешни тест(а)
  • 3 неуспешни тест(а)

Код

import re
LOCAL_FORMAT = r'\b0([1-9]|[ ()-]{1,2}\d)([ ()-]{,2}\d){5,10}\b'
INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([ ()-]{,2}\d){6,11}\b'
DOMAIN = r'(([a-zA-Z\d]\.)|([a-zA-Z\d][-a-zA-Z\d]{,61}[a-zA-Z\d])\.)+'
TLD = r'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?'
USERNAME = r'[a-zA-Z\d][\w\+\.-]{,200}'
DATE = r'[0-9]{4}-(0[1-9]|10|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
TIME = r'(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
BYTE = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
THREE_BYTES = r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
NUMBER = r'-?(0|[1-9][0-9]*)(\.[0-9]+)?'
INTEGER = r'-?(0|[1-9][0-9]*)'
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def local_format_phone_filtered(self, text):
return re.sub(LOCAL_FORMAT, '[PHONE]', text)
def international_format_phone_filtered(self, text):
return re.sub(INTERNATIONAL_FORMAT, '[PHONE]', text)
def partially_international_format_phone(self, text):
match = re.search(INTERNATIONAL_FORMAT, text)
code = match.group(1)
return re.sub(INTERNATIONAL_FORMAT, code + " [FILTERED]", text)
def email_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return re.sub(pattern, '[EMAIL]', text)
def email_components_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
match = re.search(pattern, text)
start, end = match.span()
username, hostname = text[start:end].split('@')
prefix = text[:start]
if len(username) < 6:
return text[:start] + "[FILTERED]@" + hostname + text[end:]
elif self.preserve_email_hostname:
return text[:start] + "[FILTERED]@" + hostname + text[end:]
return prefix + username[0:3] + '[FILTERED]@' + hostname + text[end:]
def filtered(self):
if self.preserve_email_hostname or\
self.partially_preserve_email_username:
result = self.email_components_filter(self.text)
else:
result = self.email_filter(self.text)
if re.search(LOCAL_FORMAT, result):
return self.local_format_phone_filtered(result)
if re.search(INTERNATIONAL_FORMAT, result) and\
self.preserve_phone_country_code:
return self.partially_international_format_phone(result)
if re.search(INTERNATIONAL_FORMAT, result):
return self.international_format_phone_filtered(result)
return result
class Validations:
@classmethod
def equal(cls, pattern, value):
match = re.search(pattern, value)
if not match:
return False
start, end = match.span()
if value[start:end] == value:
return True
return False
@classmethod
def is_email(cls, value):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_phone(csl, value):
if Validations.equal(INTERNATIONAL_FORMAT, value) or\
Validations.equal(LOCAL_FORMAT, value):
return True
return False
@classmethod
def is_hostname(cls, value):
pattern = r'\b' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_ip_address(cls, value):
pattern = THREE_BYTES + BYTE
return Validations.equal(pattern, value)
@classmethod
def is_number(cls, value):
pattern = NUMBER
return Validations.equal(pattern, value)
@classmethod
def is_integer(cls, value):
pattern = INTEGER
return Validations.equal(pattern, value)
@classmethod
def is_date(cls, value):
pattern = DATE
return Validations.equal(pattern, value)
@classmethod
def is_time(cls, value):
pattern = TIME
return Validations.equal(pattern, value)
@classmethod
def is_datetime(cls, value):
pattern = DATE + r'( |T)' + TIME
return Validations.equal(pattern, value)

Лог от изпълнението

...EF...........F......................
======================================================================
ERROR: test_does_not_filter_invalid_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-zpca4n/test.py", line 50, in test_does_not_filter_invalid_emails
    self.assertEqual(text, self.filter_email_usernames(text))
  File "/tmp/d20140513-11348-zpca4n/test.py", line 11, in filter_email_usernames
    return filter.filtered()
  File "/tmp/d20140513-11348-zpca4n/solution.py", line 54, in filtered
    result = self.email_components_filter(self.text)
  File "/tmp/d20140513-11348-zpca4n/solution.py", line 42, in email_components_filter
    start, end = match.span()
AttributeError: 'NoneType' object has no attribute 'span'

======================================================================
FAIL: test_does_not_filter_invalid_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-zpca4n/test.py", line 86, in test_does_not_filter_invalid_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
AssertionError: '0005551234569' != '0[PHONE]'
- 0005551234569
+ 0[PHONE]


======================================================================
FAIL: test_can_validate_more_complex_phone_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-zpca4n/test.py", line 160, in test_can_validate_more_complex_phone_numbers
    self.assertIs(solution.Validations.is_phone(phone), valid)
AssertionError: True is not False

----------------------------------------------------------------------
Ran 39 tests in 0.056s

FAILED (failures=2, errors=1)

История (4 версии и 0 коментара)

Евгени обнови решението на 21.04.2014 22:22 (преди над 10 години)

+import re
+
+
+LOCAL_FORMAT = r'\b0([\s()-]{,2}\d){6,11}\b'
+INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([\s()-]{,2}\d){6,11}\b'
+DOMAIN = r'(([a-zA-Z\d]\.)|([a-zA-Z\d][-a-zA-Z\d]{,61}[a-zA-Z\d])\.)+'
+TLD = r'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?'
+USERNAME = r'[a-zA-Z\d][\w\+\.-]{,200}'
+DATE = r'[0-9]{4}-(0[1-9]|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
+TIME = r'(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
+BYTE = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
+THREE_BYTES = r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
+NUMBER = r'-?(0|[1-9][0-9]*)(\.[0-9]+)?'
+INTEGER = r'-?(0|[1-9][0-9]*)'
+
+
+class PrivacyFilter:
+ def __init__(self, text):
+ self.text = text
+ self.preserve_phone_country_code = False
+ self.preserve_email_hostname = False
+ self.partially_preserve_email_username = False
+
+ def local_format_phone_filtered(self, text):
+ return re.sub(LOCAL_FORMAT, '[PHONE]', text)
+
+ def international_format_phone_filtered(self, text):
+ return re.sub(INTERNATIONAL_FORMAT, '[PHONE]', text)
+
+ def partially_international_format_phone(self, text):
+ match = re.search(INTERNATIONAL_FORMAT, text)
+ code = match.group(1)
+ return re.sub(INTERNATIONAL_FORMAT, code + " [FILTERED]", text)
+
+ def email_filter(self, text):
+ pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
+ return re.sub(pattern, '[EMAIL]', text)
+
+ def email_components_filter(self, text):
+ pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
+ match = re.search(pattern, text)
+ start, end = match.span()
+ username, hostname = text[start:end].split('@')
+ if len(username) < 6:
+ return "[FILTERED]@" + hostname
+ elif self.preserve_email_hostname:
+ return "[FILTERED]@" + hostname
+ return username[0:3] + '[FILTERED]@' + hostname
+
+ def filtered(self):
+ if self.preserve_email_hostname or\
+ self.partially_preserve_email_username:
+ result = self.email_components_filter(self.text)
+ else:
+ result = self.email_filter(self.text)
+ if re.search(LOCAL_FORMAT, result):
+ return self.local_format_phone_filtered(result)
+ if re.search(INTERNATIONAL_FORMAT, result) and\
+ self.preserve_phone_country_code:
+ return self.partially_international_format_phone(result)
+ if re.search(INTERNATIONAL_FORMAT, result):
+ return self.international_format_phone_filtered(result)
+ return result
+
+
+class Validations:
+ @classmethod
+ def equal(cls, pattern, value):
+ match = re.search(pattern, value)
+ if not match:
+ return False
+ start, end = match.span()
+ if value[start:end] == value:
+ return True
+ return False
+
+ @classmethod
+ def is_email(cls, value):
+ pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_phone(csl, value):
+ if Validations.equal(INTERNATIONAL_FORMAT, value) or\
+ Validations.equal(LOCAL_FORMAT, value):
+ return True
+ return False
+
+ @classmethod
+ def is_hostname(cls, value):
+ pattern = r'\b' + DOMAIN + TLD + r'\b'
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_ip_address(cls, value):
+ pattern = THREE_BYTES + BYTE
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_number(cls, value):
+ pattern = NUMBER
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_integer(cls, value):
+ pattern = INTEGER
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_date(cls, value):
+ pattern = DATE
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_time(cls, value):
+ pattern = TIME
+ return Validations.equal(pattern, value)
+
+ @classmethod
+ def is_datetime(cls, value):
+ pattern = DATE + r'( |T)' + TIME
+ return Validations.equal(pattern, value)

Евгени обнови решението на 22.04.2014 11:30 (преди над 10 години)

import re
-LOCAL_FORMAT = r'\b0([\s()-]{,2}\d){6,11}\b'
+LOCAL_FORMAT = r'\b0([1-9]|[\s()-]{1,2}\d)([\s()-]{,2}\d){5,10}\b'
INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([\s()-]{,2}\d){6,11}\b'
DOMAIN = r'(([a-zA-Z\d]\.)|([a-zA-Z\d][-a-zA-Z\d]{,61}[a-zA-Z\d])\.)+'
TLD = r'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?'
USERNAME = r'[a-zA-Z\d][\w\+\.-]{,200}'
DATE = r'[0-9]{4}-(0[1-9]|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
TIME = r'(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
BYTE = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
THREE_BYTES = r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
NUMBER = r'-?(0|[1-9][0-9]*)(\.[0-9]+)?'
INTEGER = r'-?(0|[1-9][0-9]*)'
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def local_format_phone_filtered(self, text):
return re.sub(LOCAL_FORMAT, '[PHONE]', text)
def international_format_phone_filtered(self, text):
return re.sub(INTERNATIONAL_FORMAT, '[PHONE]', text)
def partially_international_format_phone(self, text):
match = re.search(INTERNATIONAL_FORMAT, text)
code = match.group(1)
return re.sub(INTERNATIONAL_FORMAT, code + " [FILTERED]", text)
def email_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return re.sub(pattern, '[EMAIL]', text)
def email_components_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
match = re.search(pattern, text)
start, end = match.span()
username, hostname = text[start:end].split('@')
if len(username) < 6:
return "[FILTERED]@" + hostname
elif self.preserve_email_hostname:
return "[FILTERED]@" + hostname
return username[0:3] + '[FILTERED]@' + hostname
def filtered(self):
if self.preserve_email_hostname or\
self.partially_preserve_email_username:
result = self.email_components_filter(self.text)
else:
result = self.email_filter(self.text)
if re.search(LOCAL_FORMAT, result):
return self.local_format_phone_filtered(result)
if re.search(INTERNATIONAL_FORMAT, result) and\
self.preserve_phone_country_code:
return self.partially_international_format_phone(result)
if re.search(INTERNATIONAL_FORMAT, result):
return self.international_format_phone_filtered(result)
return result
class Validations:
@classmethod
def equal(cls, pattern, value):
match = re.search(pattern, value)
if not match:
return False
start, end = match.span()
if value[start:end] == value:
return True
return False
@classmethod
def is_email(cls, value):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_phone(csl, value):
if Validations.equal(INTERNATIONAL_FORMAT, value) or\
Validations.equal(LOCAL_FORMAT, value):
return True
return False
@classmethod
def is_hostname(cls, value):
pattern = r'\b' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_ip_address(cls, value):
pattern = THREE_BYTES + BYTE
return Validations.equal(pattern, value)
@classmethod
def is_number(cls, value):
pattern = NUMBER
return Validations.equal(pattern, value)
@classmethod
def is_integer(cls, value):
pattern = INTEGER
return Validations.equal(pattern, value)
@classmethod
def is_date(cls, value):
pattern = DATE
return Validations.equal(pattern, value)
@classmethod
def is_time(cls, value):
pattern = TIME
return Validations.equal(pattern, value)
@classmethod
def is_datetime(cls, value):
pattern = DATE + r'( |T)' + TIME
return Validations.equal(pattern, value)

Евгени обнови решението на 22.04.2014 22:32 (преди над 10 години)

import re
LOCAL_FORMAT = r'\b0([1-9]|[\s()-]{1,2}\d)([\s()-]{,2}\d){5,10}\b'
INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([\s()-]{,2}\d){6,11}\b'
DOMAIN = r'(([a-zA-Z\d]\.)|([a-zA-Z\d][-a-zA-Z\d]{,61}[a-zA-Z\d])\.)+'
TLD = r'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?'
USERNAME = r'[a-zA-Z\d][\w\+\.-]{,200}'
-DATE = r'[0-9]{4}-(0[1-9]|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
+DATE = r'[0-9]{4}-(0[1-9]|10|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
TIME = r'(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
BYTE = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
THREE_BYTES = r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
NUMBER = r'-?(0|[1-9][0-9]*)(\.[0-9]+)?'
INTEGER = r'-?(0|[1-9][0-9]*)'
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def local_format_phone_filtered(self, text):
return re.sub(LOCAL_FORMAT, '[PHONE]', text)
def international_format_phone_filtered(self, text):
return re.sub(INTERNATIONAL_FORMAT, '[PHONE]', text)
def partially_international_format_phone(self, text):
match = re.search(INTERNATIONAL_FORMAT, text)
code = match.group(1)
return re.sub(INTERNATIONAL_FORMAT, code + " [FILTERED]", text)
def email_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return re.sub(pattern, '[EMAIL]', text)
def email_components_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
match = re.search(pattern, text)
start, end = match.span()
username, hostname = text[start:end].split('@')
if len(username) < 6:
return "[FILTERED]@" + hostname
elif self.preserve_email_hostname:
return "[FILTERED]@" + hostname
return username[0:3] + '[FILTERED]@' + hostname
def filtered(self):
if self.preserve_email_hostname or\
self.partially_preserve_email_username:
result = self.email_components_filter(self.text)
else:
result = self.email_filter(self.text)
if re.search(LOCAL_FORMAT, result):
return self.local_format_phone_filtered(result)
if re.search(INTERNATIONAL_FORMAT, result) and\
self.preserve_phone_country_code:
return self.partially_international_format_phone(result)
if re.search(INTERNATIONAL_FORMAT, result):
return self.international_format_phone_filtered(result)
return result
class Validations:
@classmethod
def equal(cls, pattern, value):
match = re.search(pattern, value)
if not match:
return False
start, end = match.span()
if value[start:end] == value:
return True
return False
@classmethod
def is_email(cls, value):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_phone(csl, value):
if Validations.equal(INTERNATIONAL_FORMAT, value) or\
Validations.equal(LOCAL_FORMAT, value):
return True
return False
@classmethod
def is_hostname(cls, value):
pattern = r'\b' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_ip_address(cls, value):
pattern = THREE_BYTES + BYTE
return Validations.equal(pattern, value)
@classmethod
def is_number(cls, value):
pattern = NUMBER
return Validations.equal(pattern, value)
@classmethod
def is_integer(cls, value):
pattern = INTEGER
return Validations.equal(pattern, value)
@classmethod
def is_date(cls, value):
pattern = DATE
return Validations.equal(pattern, value)
@classmethod
def is_time(cls, value):
pattern = TIME
return Validations.equal(pattern, value)
@classmethod
def is_datetime(cls, value):
pattern = DATE + r'( |T)' + TIME
return Validations.equal(pattern, value)

Евгени обнови решението на 23.04.2014 00:34 (преди над 10 години)

import re
-LOCAL_FORMAT = r'\b0([1-9]|[\s()-]{1,2}\d)([\s()-]{,2}\d){5,10}\b'
-INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([\s()-]{,2}\d){6,11}\b'
+LOCAL_FORMAT = r'\b0([1-9]|[ ()-]{1,2}\d)([ ()-]{,2}\d){5,10}\b'
+INTERNATIONAL_FORMAT = r'((00|\+)[1-9]\d{0,2})([ ()-]{,2}\d){6,11}\b'
DOMAIN = r'(([a-zA-Z\d]\.)|([a-zA-Z\d][-a-zA-Z\d]{,61}[a-zA-Z\d])\.)+'
TLD = r'[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?'
USERNAME = r'[a-zA-Z\d][\w\+\.-]{,200}'
DATE = r'[0-9]{4}-(0[1-9]|10|11|12)-(0[1-9]|((1|2)[0-9])|(3[0-1]))'
TIME = r'(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
BYTE = r'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
THREE_BYTES = r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
NUMBER = r'-?(0|[1-9][0-9]*)(\.[0-9]+)?'
INTEGER = r'-?(0|[1-9][0-9]*)'
class PrivacyFilter:
def __init__(self, text):
self.text = text
self.preserve_phone_country_code = False
self.preserve_email_hostname = False
self.partially_preserve_email_username = False
def local_format_phone_filtered(self, text):
return re.sub(LOCAL_FORMAT, '[PHONE]', text)
def international_format_phone_filtered(self, text):
return re.sub(INTERNATIONAL_FORMAT, '[PHONE]', text)
def partially_international_format_phone(self, text):
match = re.search(INTERNATIONAL_FORMAT, text)
code = match.group(1)
return re.sub(INTERNATIONAL_FORMAT, code + " [FILTERED]", text)
def email_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return re.sub(pattern, '[EMAIL]', text)
def email_components_filter(self, text):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
match = re.search(pattern, text)
start, end = match.span()
username, hostname = text[start:end].split('@')
+ prefix = text[:start]
if len(username) < 6:
- return "[FILTERED]@" + hostname
+ return text[:start] + "[FILTERED]@" + hostname + text[end:]
elif self.preserve_email_hostname:
- return "[FILTERED]@" + hostname
- return username[0:3] + '[FILTERED]@' + hostname
+ return text[:start] + "[FILTERED]@" + hostname + text[end:]
+ return prefix + username[0:3] + '[FILTERED]@' + hostname + text[end:]
def filtered(self):
if self.preserve_email_hostname or\
self.partially_preserve_email_username:
result = self.email_components_filter(self.text)
else:
result = self.email_filter(self.text)
if re.search(LOCAL_FORMAT, result):
return self.local_format_phone_filtered(result)
if re.search(INTERNATIONAL_FORMAT, result) and\
self.preserve_phone_country_code:
return self.partially_international_format_phone(result)
if re.search(INTERNATIONAL_FORMAT, result):
return self.international_format_phone_filtered(result)
return result
class Validations:
@classmethod
def equal(cls, pattern, value):
match = re.search(pattern, value)
if not match:
return False
start, end = match.span()
if value[start:end] == value:
return True
return False
@classmethod
def is_email(cls, value):
pattern = r'\b' + USERNAME + r'@' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_phone(csl, value):
if Validations.equal(INTERNATIONAL_FORMAT, value) or\
Validations.equal(LOCAL_FORMAT, value):
return True
return False
@classmethod
def is_hostname(cls, value):
pattern = r'\b' + DOMAIN + TLD + r'\b'
return Validations.equal(pattern, value)
@classmethod
def is_ip_address(cls, value):
pattern = THREE_BYTES + BYTE
return Validations.equal(pattern, value)
@classmethod
def is_number(cls, value):
pattern = NUMBER
return Validations.equal(pattern, value)
@classmethod
def is_integer(cls, value):
pattern = INTEGER
return Validations.equal(pattern, value)
@classmethod
def is_date(cls, value):
pattern = DATE
return Validations.equal(pattern, value)
@classmethod
def is_time(cls, value):
pattern = TIME
return Validations.equal(pattern, value)
@classmethod
def is_datetime(cls, value):
pattern = DATE + r'( |T)' + TIME
return Validations.equal(pattern, value)