0

I am already using string.letters, string.digits and string.hexdigits to validate some of my User Input Fields. However, I have a need to validate a floating point number but cannot seem to find an equivalent call. No decimal point is acceptable as is one, but two or more should flag an Error! Is there function for this or do I need write my own validation routine?

Thank you...

MichaelJohn
  • 185
  • 3
  • 15

1 Answers1

2

There is one, but it doesn't work for decimal points. You could easily write what you want, however, by catching the ValueError:

def is_numeric_inc_point(s):
    try:
        float(s)
    except ValueError:
        return False
    return True

Demo:

>>> is_numeric_inc_point('5')
True
>>> is_numeric_inc_point('4.8')
True
>>> is_numeric_inc_point('6..2')
False
anon582847382
  • 19,907
  • 5
  • 54
  • 57