Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static boolean validateCardNumber(String n) { n = n.replace(" ", ""); int j = n.length(); String[] s1 = new String[j]; for (int i = 0; i < n.length(); i++) s1[i] = "" + n.charAt(i); int checksum = 0; for (int i = s1.length - 1; i >= 0; i -= 2) { int k = 0; if (i > 0) { k = Integer.valueOf(s1[i - 1]) * 2; if (k > 9) { String s = "" + k; k = Integer.valueOf(s.substring(0, 1)) + Integer.valueOf(s.substring(1)); } checksum += Integer.valueOf(s1[i]) + k; } else checksum += Integer.valueOf(s1[0]); } return ((checksum % 10) == 0); } }