All pastes #283194 Raw Edit

p4l / isinteger

public text v1 · immutable
#283194 ·published 2006-12-18 04:21 UTC
rendered paste body
###btw i didnt code this. found it today :)



# Returns 1 if v is an well-formed integer,
# and 0 otherwise. Does not work for floats.
#
proc isinteger {v} {
    return [regexp {^[+-]?[0-9]+$} $v]
}

# Returns 1 if v is an well-formed float,
# and 0 otherwise. Works also for floats with
# mantisse and exponent... and of course for integers.
#
proc isfloat {v} {
    return [regexp {^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.[0-9]*)|([0-9]+))((e|E)[+-]?[0-9]+)?$} $v]
}