Jump to content

From validation in jquery


bamfon

Recommended Posts

Before I write anything I will just so I have VERY basic know how of Javascript, don't really use it so have not learnt it 

 

Using jquery to validate a simple form, but it keep breaking on the password part, I am sure I done everything by the book and right

 

 

I plan on adding this to my CMS, I used to do it all by PHP but that way is longer and does not look as nice as jquery does


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js"></script>

<form id="myform">
     <input type="text" name="username" />
    <br/>
    <input type="text" name="email" />
    <br/>
    <input type="text" name="password" />
    <br/>
   <input type="text" name="confirm_password" />
    <br/>
    <input type="submit" />
</form>
<a id="docs" href="http://docs.jquery.com/Plugins/Validation" target="_blank">Validation Documentation</a>
$(document).ready(function () {

    $('#myform').validate({ // initialize the plugin
        rules: {
            username: {
				required: true,
				minlength: 5
			},
            email: {
				required: true,
				email: true
			},
            password: {
				required: true,
                minlength: 5,
                maxlength: 15,
                ContainsAtLeastOneDigit: true
			},
			confirm_password: {
				required: true,
				equalTo: "#password"
			},
                                
        },
        messages: {
			
			username: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 5 characters"
			},
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at between 6 to 14 characters long",
                maxlength: "Your password must be at between 6 to 14 characters long11",
                ContainsAtLeastOneDigit: "must contaion one number"
			},
			confirm_password: {
				required: "Please confirm passwordd",
				equalTo: "Please enter the same password as above"
			},
			email: "Please enter a valid email address",
                  
		},
        submitHandler: function (form) { // for demo
            alert('valid form submitted'); // for demo
            return false; // for demo
        }
    });

});
Link to comment
Share on other sites

What does Firebug say?

 

If the error's in Javascript it should be throwing exceptions automagically...

That's the thing, there no error, when you try to put in password, even if you have between 5-15 characters long and have a number, the message does not go away and page does not submit :S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.