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

Haciendo eso me tira otro error.
Teniendo en cuenta que el código ahora es así:
Código:
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]$/";
var codigo=document.getElementById('isbn');
function validar() {
if (regex.test()) {
  // Remove non ISBN digits, then split into an array
  var chars = codigo.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");
}
}
Me da el error Uncaught TypeError: Object /^(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}$|[-0-9X ]{13}$|?[0-9X]{10}$)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]$/ has no method 'test'