Click here to Skip to main content
15,880,651 members
Articles / Web Development / HTML
Article

ISBN13 Validation

Rate me:
Please Sign up or sign in to vote.
2.83/5 (3 votes)
27 Mar 2007CPOL2 min read 43.9K   809   14   8
Validating ISBN13 numbers on format and correct checksum in class or CustomValidator (ISBN: book reference numbers)
Example in ASP.NET and WinForms

Introduction

This is my first article and hopefully not the last. I was looking for a good and simple article to start with. I hope this is a good start and that you guys can use my code.

The function of this article is to explain the possibilities of the ISBN13 validation object I created. It validates a few different things specified by ISBN International. I will explain them in this article.

Background

The basic idea behind ISBN numbers is code standard for books. For those of you who want to know more about ISBN, here is some info from Wikipedia and ISBN International.

Related Articles

There is another article (ASP.NET ISBN Validator) on The Code Project about ISBN validation. However, there are a few differences.

This code:

  • is written in C#
  • has a separate ISBN13 validation class
  • validates on grouped and ungroup ISBN13 numbers
  • only validates ISBN13 numbers (this is the standard at the moment)

Using the Code

The code is very basic and straightforward. The library has a class ISBN.ISBN13. Here is an example code to show the use of the class. As you can see, the constructor has an overload to input the ISBN directly.

C#
ISBN.ISBN13 isbnValid = new ISBN13();
isbnValid.ISBN = "978-0-571-08989-5";

ISBN.ISBN13 isbnValid2 = new ISBN13("978-0-571-08989-5");

Validation is done directly when the ISBN is set. You can see if it is valid with the IsValid property.

ISBN13 also has some static methods that are interesting. These are easy to use.

  • C#
    IsValidISBN(string isbn) : bool 
  • C#
    GetISBNFormat(string isbn) : ISBNGroupingFormat 
  • C#
    ValidateChecksum(string isbn) : bool 

To use the validator control, add the ToolboxItem. This way you can drag and drop the control. It is inherited from the CustomValidator control. The validation is done by the ISBN13 class.

You can also add this to use the ISBN validator in your ASP form.

ASP.NET
    <%@ register assembly="ISBN" namespace="ISBN.Web" tagprefix="cc1" %> 
    <%cc1:isbn13validator controltovalidate="TextBox1" 
    runat="server" id="ISBN13Validator1"%> 
</cc1:isbn13validator%>

Points of Interest

One of the most interesting points to look at is the wild RegEx string used to validate the grouped ISBN. Is my first RegEx this long?

History

  • 27th March, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
I started with classic ASP in 2000 after done a lot of HTML stuff. I wanted more dynamic things. Before that time I told a friend I would never start to program. To complicated. When I started to do it I was sold immediatly.

In about 2005 I started to build ASP.NET app's. Lately I liked to make .NET Forms more.

Comments and Discussions

 
QuestionError? Pin
Member 153090917-Nov-09 4:41
Member 153090917-Nov-09 4:41 
I think there's a bug in the ValidatedChecksum(string isbn) method.
If the line:
int CheckSum = 10 - Mod;
produces 10 (because Mod is 0) then the method returns false because the last digit is not "10" but 0.

But as I see it a ISBN13 number like 9780061906060 is valid.
So you could add:
if (CheckSum == 10) CheckSum = 0;

in the next line.
GeneralSimple code [modified] Pin
NightCrawler03X23-Nov-08 1:07
NightCrawler03X23-Nov-08 1:07 
Questionyou do know about regular expression validator? Pin
Thanks for all the fish27-Mar-07 9:05
Thanks for all the fish27-Mar-07 9:05 
AnswerRe: you do know about regular expression validator? Pin
Thomas Weidenmueller27-Mar-07 10:34
Thomas Weidenmueller27-Mar-07 10:34 
GeneralRe: you do know about regular expression validator? Pin
Matglas27-Mar-07 20:22
Matglas27-Mar-07 20:22 
AnswerRe: you do know about regular expression validator? Pin
Matglas27-Mar-07 22:42
Matglas27-Mar-07 22:42 
GeneralWhy make it more complicated than necessary Pin
ednrgc27-Mar-07 8:40
ednrgc27-Mar-07 8:40 
GeneralRe: Why make it more complicated than necessary [modified] Pin
Matglas27-Mar-07 20:24
Matglas27-Mar-07 20:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.