I have a string input by the user that should represent an IP address like: 123.234.12.8 but being a silly person as they can be sometimes what if they enter: 12#.234.1@.8
I've figured out how check for characters and symbols by looping through the string and making temporary chars/ints using:
tempChar = ipString.charAt(i);
tempInt = Character.getNumericValue(tempChar);
I can flag a 'a' or a 'q' but I can't differentiate between the '.' symbol and others such as '#' or '&' because they're all given the int value -1.
Is there an existing method for preventing users entering any symbol except a '.' or can someone point me in the right direction if I'm going about this wrong?
EDIT: This is in Java.