Created
September 20, 2011 21:05
-
-
Save starenka/1230328 to your computer and use it in GitHub Desktop.
dummy phone nr check
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import unittest | |
pattern = re.compile(r'^(\+?(00)?\s?\d{2,3}[-\.\s]?)?((\d{2,3})[-\.\s]?){3,}$') | |
class ReTest(unittest.TestCase): | |
NOMNOM = ('728 889 137', | |
'72 88 91 37', | |
'72.88.91.37', | |
'72-88-91-37', | |
'728-889-137', | |
'728.889.137', | |
'+420 728 889 137', | |
'00 420 728 889 137', | |
'+420.728.889.137' | |
) | |
MEH = ('7288', | |
'72889', | |
'728x813', | |
'++420 728 889137', | |
) | |
def test_ok(self): | |
for expr in self.NOMNOM: | |
print expr | |
self.assertTrue(bool(re.search(pattern,expr))) | |
def test_bad(self): | |
for expr in self.MEH: | |
print expr | |
self.assertFalse(bool(re.search(pattern,expr))) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment