?
Solved

ISBN Regular Expression

Posted on 2004-08-09
4
Medium Priority
?
668 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

762 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