Yesterday in an online interview, the interviewer asked me this question:If I give you a string, you have to return if a string is number or  not. You are not allowed to use any parse function available.This was my first online interview after a long long time, so I took way too much time in this question. I want to gather feedback about my solution and better ideas for the solution to this problem. You can ignore complex numbers for now.public static boolean isNumber(String toTest) {    boolean isNegativeFoundAlready = false;    boolean isDecimalPointFoundAlready = false;    for (int i=0; i < toTest.length(); i++) {        if (!0123456789-..contains(new String(new char[]{toTest.charAt(i)}))) {            return false;        } else {            if ('-' == toTest.charAt(i) && i != 0) {                return false;            }            if ('-' == toTest.charAt(i) && (i == toTest.length() - 1)) {                return false;            }            if ('-' == toTest.charAt(i) && isNegativeFoundAlready) {                return false;            }            if ('-' == toTest.charAt(i)) {                isNegativeFoundAlready = true;            }            if ('.' == toTest.charAt(i) && isDecimalPointFoundAlready) {                return false;            }            if ('.' == toTest.charAt(i)) {                isDecimalPointFoundAlready = true;            }            if ('.' == toTest.charAt(i) && (i == toTest.length() - 1)) {                return false;            }        }    }    return true;}Test cases I ran:    System.out.println(123 isNumber?  + isNumber(123));    System.out.println(.123 isNumber?  + isNumber(.123));    System.out.println(-.123 isNumber?  + isNumber(-.123));    System.out.println(-. isNumber?  + isNumber(-.));    System.out.println(.- isNumber?  + isNumber(.-));    System.out.println(23.34.545 isNumber?  + isNumber(23.34.545));    System.out.println(- isNumber?  + isNumber(-));    System.out.println(-0 isNumber?  + isNumber(-0));    System.out.println(12$%^&*# isNumber?  + isNumber(12$%^&*#));
Given a String, return a boolean if it is a number
java;algorithm;strings;interview questions;validation