org.apache.commons.validator

Class ISBNValidator

public class ISBNValidator extends Object

A class for validating 10 digit ISBN codes. Based on this algorithm

Since: Validator 1.2.0

Version: $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $

Field Summary
static StringCHECK
static StringGROUP
static StringISBN_PATTERN
ISBN consists of 4 groups of numbers separated by either dashes (-) or spaces.
static StringPUBLISHER
static StringSEP
static StringTITLE
Constructor Summary
ISBNValidator()
Default Constructor.
Method Summary
Stringclean(String isbn)
Removes all non-digit characters except for 'X' which is a valid ISBN character.
booleanisFormatted(String isbn)
Returns true if the ISBN contains one of the separator characters space or dash.
booleanisValid(String isbn)
If the ISBN is formatted with space or dash separators its format is validated.
booleanisValidPattern(String isbn)
Returns true if the ISBN is formatted properly.
intsum(String isbn)
Returns the sum of the weighted ISBN characters.
inttoInt(char ch)
Returns the numeric value represented by the character.

Field Detail

CHECK

private static final String CHECK

GROUP

private static final String GROUP

ISBN_PATTERN

private static final String ISBN_PATTERN
ISBN consists of 4 groups of numbers separated by either dashes (-) or spaces. The first group is 1-5 characters, second 1-7, third 1-6, and fourth is 1 digit or an X.

PUBLISHER

private static final String PUBLISHER

SEP

private static final String SEP

TITLE

private static final String TITLE

Constructor Detail

ISBNValidator

public ISBNValidator()
Default Constructor.

Method Detail

clean

private String clean(String isbn)
Removes all non-digit characters except for 'X' which is a valid ISBN character.

isFormatted

private boolean isFormatted(String isbn)
Returns true if the ISBN contains one of the separator characters space or dash.

isValid

public boolean isValid(String isbn)
If the ISBN is formatted with space or dash separators its format is validated. Then the digits in the number are weighted, summed, and divided by 11 according to the ISBN algorithm. If the result is zero, the ISBN is valid. This method accepts formatted or raw ISBN codes.

Parameters: isbn Candidate ISBN number to be validated. null is considered invalid.

Returns: true if the string is a valid ISBN code.

isValidPattern

private boolean isValidPattern(String isbn)
Returns true if the ISBN is formatted properly.

sum

private int sum(String isbn)
Returns the sum of the weighted ISBN characters.

toInt

private int toInt(char ch)
Returns the numeric value represented by the character. If the character is not a digit but an 'X', 10 is returned.
Copyright (c) 2001-2004 Apache Software Foundation