views:

124

answers:

1

I have written a custom validation code in jQuery, which is working fine. I have a login form which has two fields, i.e. userid and password. I have written a custom code for client side validation for these fields. This code is working fine and gives me proper error messages as per the situation.

But the problem with this code is that when I enter the invalid data in any or both field and press submit button of form then it displays the proper error message but at the same time when I checked it in Firebug it displays following error message when submit button of the form is clicked

validate is not defined
function onclick(event) { javascript: return validate(); }
(click clientX=473, clientY=273)

Here is the JQUERY validation code

$(document).ready(function (){

$("#id_login_form").validate({

        rules: {

            userid: {

                required: true,

                minlength: 6,

                maxlength: 20,

//                              basic: true

                            },

            password: {

                required: true,

                minlength: 6,

                maxlength: 15,

//              basic: true

                              }

               },

    messages: {

        userid: {

            required: "<br> Please enter the username.",

            minlength: "<br>User Name should be minimum 6 characters long.",

            maxlength: "<br>User Name should be maximum 15 characters long.",

//          basic: "<br>working here"

              },

        password: {

            required: "<br> Please enter the password.",

            minlength: "<br>Password should be minimum 6 characters long.",

            maxlength: "<br>Password should be maximum 15 characters long.",

//          basic: "<br>working here too.",

              }

          },

        errorClass: "errortext",

        errorLabelContainer: "#messagebox"
                                             }
    });

    });

/*  $.validator.addMethod('username_alphanum', function (value) { 
    return /^(?![0-9]+$)[a-zA-Z 0-9_.]+$/.test(value); 
    }, 'User name should be alphabetic or Alphanumeric and may contain . and _.');


    $.validator.addMethod('alphanum', function (value) { 
    return /^(?![a-zA-Z]+$)(?![0-9]+$)[a-zA-Z 0-9]+$/.test(value); 
    }, 'Password should be Alphanumeric.');


    $.validator.addMethod('basic', function (value) { 
    return /^[a-zA-Z 0-9_.]+$/.test(value); 
    }, 'working working working');
*/

So please tell me where is I am wrong in my jQuery code. Thank You!

A: 

Although your code is far for complete, my crystal ball suggests that you are copying some code you found somewhere, without noticing that the code is not plain jQuery code. The code belongs to a jQuery plugin so you must identify what plugin it is, get it and load the appropriate *.js file before you use it.

Álvaro G. Vicario
It looks like the [jQuery Validation plugin](http://docs.jquery.com/Plugins/Validation).
Petri Pennanen