Showing posts with label not digits. Show all posts
Showing posts with label not digits. Show all posts

Wednesday, November 13, 2013

Java - Replace all non digits with an empty character in a string

String cardNumber = "4444 3333 2222 111");
cardNumber = cardNumber.trim();
cardNumber = cardNumber.replaceAll("\\D+", "");

Output:
4444333322221111