org.apache.commons.validator
Class ISBNValidator

java.lang.Object
  extended by org.apache.commons.validator.ISBNValidator

public class ISBNValidator
extends java.lang.Object

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

Since:
Validator 1.2.0

Field Summary
private static java.lang.String CHECK
           
private static java.lang.String GROUP
           
private static java.lang.String ISBN_PATTERN
          ISBN consists of 4 groups of numbers separated by either dashes (-) or spaces.
private static java.lang.String PUBLISHER
           
private static java.lang.String SEP
           
private static java.lang.String TITLE
           
 
Constructor Summary
ISBNValidator()
          Default Constructor.
 
Method Summary
private  java.lang.String clean(java.lang.String isbn)
          Removes all non-digit characters except for 'X' which is a valid ISBN character.
private  boolean isFormatted(java.lang.String isbn)
          Returns true if the ISBN contains one of the separator characters space or dash.
 boolean isValid(java.lang.String isbn)
          If the ISBN is formatted with space or dash separators its format is validated.
private  boolean isValidPattern(java.lang.String isbn)
          Returns true if the ISBN is formatted properly.
private  int sum(java.lang.String isbn)
          Returns the sum of the weighted ISBN characters.
private  int toInt(char ch)
          Returns the numeric value represented by the character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEP

private static final java.lang.String SEP
See Also:
Constant Field Values

GROUP

private static final java.lang.String GROUP
See Also:
Constant Field Values

PUBLISHER

private static final java.lang.String PUBLISHER
See Also:
Constant Field Values

TITLE

private static final java.lang.String TITLE
See Also:
Constant Field Values

CHECK

private static final java.lang.String CHECK
See Also:
Constant Field Values

ISBN_PATTERN

private static final java.lang.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.

See Also:
Constant Field Values
Constructor Detail

ISBNValidator

public ISBNValidator()
Default Constructor.

Method Detail

isValid

public boolean isValid(java.lang.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.

sum

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


clean

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


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.


isFormatted

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


isValidPattern

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



Copyright (c) 2001-2004 Apache Software Foundation