Solved

ISBN Regular Expression

Posted on 2004-08-09
4
661 Views
Last Modified: 2012-06-21
I've got the following code:

function validateISBN(isbn)
{
      if(isbn.length <= 0)
      {
            return true;
      }
      var expression = new RegExp("(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$");

      if (!expression.test(isbn) )
            return false;      
      else
            return true;
      }

but it doesn't appear to work properly. I've taken the RegExp from some ASP code but I'm still very new at this and was wondering if anyone could see where I was going wrong?

Thanx
0
Comment
Question by:Steven O'Neill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 11751705
You are wrong with teh escape character back slash.
If you need one escape character then you need to write two of them.
That is only in String.
To avoid the problem creat the RegExp in its short form.
Like this:
 var expression = /(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$/;

0
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 11751724
In oposite to the short form does the String parameter form looks like this:
 var expression = new RegExp("(?=.{13}$)\\d{1,5}([- ])\\d{1,7}\\1\\d{1,6}\\1(\\d|X)$");

0
 
LVL 2

Author Comment

by:Steven O'Neill
ID: 11751773
Zvonko

I'm sure the short form works but I've used thge string parameter form.

Thanx
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11751796
Thanks for points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question