Create a validate form in jquery -


how many types of functions or methods validate username , password?

i have tried codes cannot understand. code different each other.

this code works

<script type="text/javascript">     $(document).ready(function() {          $.validator.addmethod("email", function(value, element) {             return this.optional(element) || /^[a-za-z0-9._-]+@[a-za-z0-9-]+\.[a-za-z.]{2,5}$/i.test(value);         }, "please enter valid email address.");          $.validator.addmethod("username", function(value, element) {             return this.optional(element) || /^[a-za-z0-9._-]{3,16}$/i.test(value);         }, "username 3-15 characters");           $.validator.addmethod("password", function(value, element) {             return this.optional(element) || /^[a-za-z0-9!@#$%^&*()_]{6,16}$/i.test(value);         }, "passwords 6-16 characters");            // validate signup form         $("#signup").validate({             rules: {                 email: "required email",                 username: "required username",                 password: "required password",              },           });      }); </script> 

but isn't working:

<script type="text/javascript">     (function($, w, d) {         var jquery4u = {};          jquery4u.util = {             setupformvalidation: function() {                 //form validation rules                 $("#register-form").validate({                     rules: {                         firstname: "required",                         lastname: "required",                         email: {                             required: true,                             email: true                         },                         password: {                             required: true,                             minlength: 5                         },                         agree: "required"                     },                     messages: {                         firstname: "please enter firstname",                         lastname: "please enter lastname",                         password: {                             required: "please provide password",                             minlength: "your password must @ least 5 characters long"                         },                         email: "please enter valid email address",                         agree: "please accept our policy"                     },                     submithandler: function(form) {                         form.submit();                     }                 });             }         }          //when dom has loaded setup form validation rules         $(d).ready(function($) {             jquery4u.util.setupformvalidation();         });      })(jquery, window, document); </script> 

what difference between them?


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -