Advertisement
Irfanmuhluster

Untitled

Apr 9th, 2017
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>jQuery validation plug-in - main demo</title>
  6.     <link rel="stylesheet" href="css/screen.css">
  7.     <script src="../lib/jquery.js"></script>
  8.     <script src="../dist/jquery.validate.js"></script>
  9.     <script>
  10.     $.validator.setDefaults({
  11.         submitHandler: function() {
  12.             alert("submitted!");
  13.         }
  14.     });
  15.  
  16.     $().ready(function() {
  17.         $.validator.addMethod("loginRegex", function(value, element) {
  18.         return this.optional(element) || /^[a-zA-Z 0-9\\_]+$/i.test(value);
  19.     }, "Username must contain only alphabet,space, numbers, or underscore.")
  20.        
  21.        
  22.        
  23.         // validate the comment form when it is submitted
  24.        
  25.  
  26.         // validate signup form on keyup and submit
  27.         $("#signupForm").validate({
  28.             rules: {
  29.                 firstname: "required",
  30.                 lastname: "required",
  31.                 username: {
  32.                     required: true,
  33.                     minlength: 2,
  34.                     loginRegex : true
  35.                 },
  36.                 password: {
  37.                     required: true,
  38.                      
  39.                     minlength: 5
  40.                 },
  41.                 confirm_password: {
  42.                     required: true,
  43.                     minlength: 5,
  44.                     equalTo: "#password"
  45.                 },
  46.                 email: {
  47.                     required: true,
  48.                     email: true
  49.                 },
  50.                
  51.                 agree: "required"
  52.             },
  53.             messages: {
  54.                 firstname: "Please enter your firstname",
  55.                 lastname: "Please enter your lastname",
  56.                 username: {
  57.                     required: "Please enter a username",
  58.                     minlength: "Your username must consist of at least 2 characters",
  59.  
  60.                 },
  61.                 password: {
  62.                     required: "Please provide a password",
  63.                     minlength: "Your password must be at least 5 characters long"
  64.                 },
  65.                 confirm_password: {
  66.                     required: "Please provide a password",
  67.                     minlength: "Your password must be at least 5 characters long",
  68.                     equalTo: "Please enter the same password as above"
  69.                 },
  70.                 email: "Please enter a valid email address",
  71.                 agree: "Please accept our policy",
  72.                
  73.             }
  74.         });
  75.  
  76.         // propose username by combining first- and lastname
  77.    
  78.     });
  79.     </script>
  80.     <style>
  81.     #commentForm {
  82.         width: 500px;
  83.     }
  84.     #commentForm label {
  85.         width: 250px;
  86.     }
  87.     #commentForm label.error, #commentForm input.submit {
  88.         margin-left: 253px;
  89.     }
  90.     #signupForm {
  91.         width: 670px;
  92.     }
  93.     #signupForm label.error {
  94.         margin-left: 10px;
  95.         width: auto;
  96.         display: inline;
  97.     }
  98.     #newsletter_topics label.error {
  99.         display: none;
  100.         margin-left: 103px;
  101.     }
  102.     </style>
  103. </head>
  104. <body>
  105. <h1 id="banner"><a href="http://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
  106. <div id="main">
  107.     <p>Default submitHandler is set to display an alert into of submitting the form</p>
  108.  
  109.     <form class="cmxform" id="signupForm" method="get" action="">
  110.         <fieldset>
  111.             <legend>Validating a complete form</legend>
  112.             <p>
  113.                 <label for="firstname">Firstname</label>
  114.                 <input id="firstname" name="firstname" type="text">
  115.             </p>
  116.             <p>
  117.                 <label for="lastname">Lastname</label>
  118.                 <input id="lastname" name="lastname" type="text">
  119.             </p>
  120.             <p>
  121.                 <label for="username">Username</label>
  122.                 <input id="username" name="username" type="text">
  123.             </p>
  124.             <p>
  125.                 <label for="password">Password</label>
  126.                 <input id="password" name="password" type="password">
  127.             </p>
  128.             <p>
  129.                 <label for="confirm_password">Confirm password</label>
  130.                 <input id="confirm_password" name="confirm_password" type="password">
  131.             </p>
  132.             <p>
  133.                 <label for="email">Email</label>
  134.                 <input id="email" name="email" type="email">
  135.             </p>
  136.             <p>
  137.                 <label for="agree">Please agree to our policy</label>
  138.                 <input type="checkbox" class="checkbox" id="agree" name="agree">
  139.             </p>
  140.            
  141.             <p>
  142.                 <input class="submit" type="submit" value="Submit">
  143.             </p>
  144.         </fieldset>
  145.     </form>
  146.  
  147.  
  148. </div>
  149. </body>
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement