Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/08/2014, 04:03
daniel7754
 
Fecha de Ingreso: abril-2012
Mensajes: 20
Antigüedad: 12 años
Puntos: 0
Respuesta: Validación de moneda (€) y entero

Buenas. Estoy trasteando con expresiones regulares. Este código lo estoy utilizando para validar una nota:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Untitled Document</title>
  5. <script type="text/javascript">
  6.  
  7. function verificarMedia(objeto){
  8.     if (!/^((10)|([0-9]([.\,][0-9]+)?))$/.test(objeto.value)){
  9.         alert("La nota media introducida en uno de los campos es incorrecta. Introduzca una nota media entre 0 y 10. Ejemplo: 8,35");
  10.         return false;
  11.     }
  12.     return true;
  13. }
  14. function validar(){
  15.     window.alert ("Hola");
  16.     return verificarMedia(document.getElementById('label'));
  17. }
  18. </head>
  19.  
  20. <form id="form1" name="form1" method="post" onsubmit="return validar();">
  21.   <label for="label">laber</label>
  22.   <input type="text" name="label" id="label" onchange="verificarMedia(this);"/>
  23. </form>
  24. <input name="" type="submit" />
  25. </body>
  26. </html>

Funciona bien al cambiar el valor, pero si envío el formulario falla. ¿Por qué puede ser esto? Seguro que es un error tonto, pero llevo un rato y no lo veo xD.

Por cierto, maycolalvarez, gracias por tu respuesta