def is_digit(thing):
if not isinstance(thing, basestring):
return ValueError('Argument needs to be of instance basestring.')
# Be nice and strip whitespace.
thing = thing.strip()
# If there is nothing there, bail.
if thing == '':
return False
# If there is more than 1 decimal, bail.
if thing.count('.') > 1:
return False
# Sort of a special case. If the number is a negative, just strip it out.
if thing.startswith('-'):
# Do another strip. We are explicitly allowing for space after the negative.
thing = thing[1:].lstrip()
# If there are characters left over after all valid characters were stripped,
# then something is invalid.
if re.sub(VALID_RE, '', thing) != '':
return False
return True