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.
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.
-
IsValidISBN(string isbn) : bool
-
GetISBNFormat(string isbn) : ISBNGroupingFormat
-
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.
<%@ 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