Skip to content

Instantly share code, notes, and snippets.

@starenka
Created September 20, 2011 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starenka/1230328 to your computer and use it in GitHub Desktop.
Save starenka/1230328 to your computer and use it in GitHub Desktop.
dummy phone nr check
#!/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