How can I use this but not return FALSE because of decimal in numbers?

public class isNumeric
{
    // This method checks if a String contains only numbers
    public boolean isNumeric(String str)
    {
        //It can't contain only numbers if it's null or empty
        if (str == null || str.length() == 0)
            return false;
        for (int i = 0; i < str.length(); i++)
        {
            //non-digit character returns false.
            if (!Character.isDigit(str.charAt(i)))
                return false;
        }
        return true;
    }
}

The most minimal change I can suggest would be to change the condition at line 12 to specify ("if !( [character is digit] || character is '.')

This would allow something like "3.4.2.3...4", though. If that bothers you, you'll have to get a bit more fancy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.