Check if number form input valid or invalid?

I want to write a function to check if any inputs from user valid or invalid. The problem here is that I dont know how to check if there are more than one decimal point appears in floating-point input?

For example:

Valid input:

123
2543.32
-15.6

Invalid input:

567.43.6
192..
2..3
..12
you can read the input into a string. do two searches (find and rfind). if the two search results are not equal, you have more than one dot in it. so the input is invalid.
after that work with a stringstream and convert the input to a float/double.
or u could use atof instead of the stringstream.
Topic archived. No new replies allowed.