def _to_python(self, value, state):
self.assert_string(value, state)
- m = re.match(u'(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?', value)
+ m = re.match(u'^(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?$', value)
# This will separate
# u'+43/512/1234567-89' => (u'43', u'512/1234567', u'89')
# u'+43/512/1234/567-89' => (u'43', u'512/1234/567', u'89')
(country, phone, extension) = m.groups()
# Phone
- if phone.find(u'//') > -1: raise formencode.Invalid(self.message('phoneFormat', state) % {'value': value}, value, state)
+ if phone.find(u'//') > -1 or phone.count('/') == 0: raise formencode.Invalid(self.message('phoneFormat', state) % {'value': value}, value, state)
# Country
if country is None:
assert v.to_python(None) == (None, None)
try:
v.to_python(u'Wrong')
- assert True, u"The value 'Wrong' must not be accepted by the validator."
+ assert False, u"The value 'Wrong' must not be accepted by the validator."
except formencode.Invalid: pass
assert v.from_python((True, False)) == u'Ja'
assert v.to_python(u'+43/512/12345678') == u'+43/512/12345678'
assert v.to_python(u'0512/1234567-89') == u'+43/512/1234567-89'
assert v.to_python(u'+43/512/1234567-89') == u'+43/512/1234567-89'
- for n in [u'0512 / 12345678', u'0512-12345678']:
+ for n in [u'0512 / 12345678', u'0512-12345678', u'0049(0)8386/8113']:
try:
v.to_python(n) # has to throw an exception
- assert True, u"The telephone number '%s' should throw an exception." % v
+ assert False, u"The telephone number '%s' should throw an exception." % n
except formencode.Invalid: pass