Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/10/2013, 04:16
yafuslae
 
Fecha de Ingreso: octubre-2012
Mensajes: 45
Antigüedad: 11 años, 6 meses
Puntos: 2
Pregunta Validación: Invalid regular expression: missing /

Hola.
Resulta que estoy intentando validar ISBNs con javascript y he encontrado en internet un script que supuestamente lo hace. El problema está en que analizando con la consola de javascript de chrome me sale un pequeño error que hace que no funcione.
El error en cuestión es:
Invalid regular expression: missing /

Y el código del script es el siguiente:
Código:
// `regex` checks for ISBN-10 or ISBN-13 format
var regex = /^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|?
[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$/;

if (regex.test(subject)) {
  // Remove non ISBN digits, then split into an array
  var chars = subject.replace(/[^0-9X]/g, "").split("");
  // Remove the final ISBN digit from `chars`, and assign it to `last`
  var last  = chars.pop();
  var sum   = 0;
  var digit = 10;
  var check;

  if (chars.length == 9) {
    // Compute the ISBN-10 check digit
    for (var i = 0; i < chars.length; i++) {
      sum += digit * parseInt(chars[i], 10);
      digit -= 1;
    }
    check = 11 - (sum % 11);
    if (check == 10) {
      check = "X";
    } else if (check == 11) {
      check = "0";
    }
  } else {
    // Compute the ISBN-13 check digit
    for (var i = 0; i < chars.length; i++) {
      sum += (i % 2 * 2 + 1) * parseInt(chars[i], 10);
    }
    check = 10 - (sum % 10);
    if (check == 10) {
      check = "0";
    }
  }

  if (check == last) {
    alert("Valid ISBN");
  } else {
    alert("Invalid ISBN check digit");
  }
} else {
  alert("Invalid ISBN");
}
Está sacado de http://my.safaribooksonline.com/book/programming/regular-expressions/9780596802837/4dot-validation-and-formatting/id2990038

¿Qué podría hacer para evitar el error y así conseguir validar al rellenar un campo input de html?