public static boolean validCreditCard(String ccNum)
    {
        boolean good = false;
        String ccPrefixes[] = {
            "51", "52", "53", "54", "55", "4", "34", "37", "6011"
        };
        if((ccNum = Text.getDigitsFromString(ccNum)) == null)
            return false;
        if(ccNum.length() > 16 || ccNum.length() < 13)
            return false;
        int i = 0;
        do
        {
            if(i >= ccPrefixes.length)
                break;
            if(ccNum.startsWith(ccPrefixes[i]))
            {
                good = true;
                break;
            }
            i++;
        } while(true);
        if(!good)
            return false;
        int sum = 0;
        int weight = (ccNum.length() - 1) % 2 + 1;
        for(i = 0; i < ccNum.length(); i++)
        {
            int curDigit = Character.digit(ccNum.charAt(i), 10);
            int product = curDigit * weight;
            sum += product <= 9 ? product : product - 9;
            weight = weight % 2 + 1;
        }

        return sum % 10 == 0;
    }