1. Registered User
Join Date
Nov 2003
Posts
18

## ISBN check

Can sum1 help me cos im writing this code which will allow me to check if any ISBN I input via keyboard is correct.

Currently iv managed to get the code which allows me to input from the keyboard and im stuck i pretty clueless bout this.

Can sum1 pls help! Thanx in advance!

2. You want to check if a string is a valid ISBN number in Java? Are you sure you're not getting confused with JavaScript?

3. If you are indeed looking for java, and not javascript, you could use this (based on php code found at http://www.planet-source-code.com/vb...Id=20&lngWId=8)
Code:
```public class ISBN {
public static boolean isValid(String ISBN) {
String theISBN=ISBN.replaceAll("[^\\dX]", "");
if(theISBN.length()!=10) return false;
int checkDigit=11;
for(int i=2; i<=10; i++) {
checkDigit+=i*(((int)theISBN.charAt(10-i))-48);
}
checkDigit=(11-(checkDigit%11));
char check=(char)(checkDigit+48);
if(checkDigit==10) check='X';
else if(checkDigit==11) check='0';

if(theISBN.charAt(9)==check) return true;
return false;
}
}```

4. Registered User
Join Date
Nov 2003
Posts
18
Hmm i was told that u had to parse the string into an integer before using it the calculation of the checksum digit.

Anyone else got any ideas?

5. In a way, I am parsing the string into an integer; in ascii, the number characters 0-9 have character codes 48-57, so by using (int)charAt(i)-48, I obtain the integer value of that character. I've tried my code on some ISBNs found on amazon.com, and then on some random permutations of numbers. It seems to work ok (ie return true for real ones and false for fake ones)

6. Registered User
Join Date
Nov 2003
Posts
18
alrite thanx