adding test function for email- and telefonnumbers.
# -*- coding: utf-8 -*-
#Copyright (C) 2009 Sandro Knauß <bugs@sandroknauss.de>
#This program is free software; you can redistribute it and/or modify it under the terms
#of the GNU General Public License as published by the Free Software Foundation;
#either version 3 of the License, or any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.
import re
from .error import NotATelNumber
class Telnumber:
re_telnum=re.compile(r'^\s*(\+)?([0-9\s\-/\(\)]){5,}\s*$')
re_land=re.compile(r'^\s*(\+|00)(?P<land>[1-9]{2})')
re_number=re.compile(r'[^0-9]')
std_land="49"
def __init__(self,number=None):
if not(number is None):
self.createNumber(number)
def createNumber(self, number):
if not self.re_telnum.match(number):
raise NotATelNumber(number)
self.land=self.std_land
land=self.re_land.match(number)
if land:
self.land=land.group("land")
number=number[land.end("land"):]
number=self.re_number.sub('',number)
if number[0]=="0":
number=number[1:]
self.number = number
def __eq__(self, y):
return ((self.number == y.number) and ( self.land == y.land))
def __ne__(self, y):
return not self.__eq__(y)