Package org.apache.commons.validator
Class ISBNValidator
- java.lang.Object
-
- 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
- Version:
- $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
-
-
Field Summary
Fields Modifier and Type Field Description 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
Constructors Constructor Description ISBNValidator()
Default Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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
-
-
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.
-
-