public static boolean verifyLuhn ( String key ) { // If there is a non digit, or it is all zeros. if ( StringUtil . isBlank ( key ) || key . matches ( ".*\\D.*" ) || key . matches ( "^[0]+$" ) ) { return false ; } return ( getLuhnRemainder ( key ) == 0 ) ; }
Verify the key with the Luhn check . If the key is all zeros then the luhn check is true but that is almost never what you want so explicitly check for zero and return false if it is .