cdiego

Jquery Validate

Apr 4th, 2012
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.55 KB | None | 0 0
  1. <html>
  2. <head>
  3.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  4.         <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"></script>
  5.         <script src="messages_es.js" type="text/javascript"></script>
  6.         <script>
  7.         //Para mostrar mensajes de error en español
  8.         //agregar el archivo messages_es.js
  9.        
  10.         //Para validar desde otras partes del documento usar
  11.         //valid()
  12.        
  13.         //Para obtener la cantidad de errores usar
  14.         //numberOfInvalids()
  15.        
  16.         //Aplicar un poco de estilos css
  17.        
  18.         $(document).ready(function()
  19.         {
  20.             $("#formulario").validate();
  21.             $("#modificar").click(function(e)
  22.             {
  23.                 e.preventDefault();
  24.                 if($("#formulario").valid()==true)
  25.                 {
  26.                     alert("Formulario Correcto");
  27.                 }
  28.                 else
  29.                 {
  30.                     alert($("#formulario").validate().numberOfInvalids() + " errores");
  31.                 }
  32.             });
  33.         });
  34.         </script>
  35.         <style>
  36.         #contenedor{margin: 0px auto; border:5px dotted #BBCC00; width:500px; heigth: 400px; padding: 10px}
  37.         label.error{display:block; color:red;}
  38.         </style>
  39. </head>
  40. <body>
  41. <div id="contenedor">
  42. <form id="formulario">
  43. <p><pre>Nombre: </pre><input type="text" name="nombre" class="required" id="nombre" /></p>
  44. <p><pre>Email: </pre><input type="text" name="correo" class="required email" id="correo" /></p>
  45. <p><pre>Link: </pre><input type="text" name="link" class="required url" id="link" /></p>
  46. <input type="submit" value="Submit"/>
  47. </form>
  48. <a href="#" id="modificar">Modificar</a>
  49. </div>
  50. <body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment