Jump to content


Photo

From validation in jquery


  • Please log in to reply
3 replies to this topic

#1 bamfon

bamfon

    Advanced Member

  • Members
  • PipPipPip
  • 82 posts

Posted 29 June 2013 - 06:51 PM

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
        }
    });

});


#2 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 281 posts
  • LocationJoplin, MO

Posted 29 June 2013 - 11:12 PM

What does Firebug say?

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


"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#3 bamfon

bamfon

    Advanced Member

  • Members
  • PipPipPip
  • 82 posts

Posted 30 June 2013 - 08:39 AM

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



#4 White_Lily

White_Lily

    Advanced Member

  • Members
  • PipPipPip
  • 521 posts

Posted 04 July 2013 - 02:43 PM

Try running the form in Chrome, as the inspect element in Chrome tells you exactly what line the error is occurring on, and whats causing it to occur.


"In order to be irreplaceable, one needs to be different from another."

CMS Development: http://cms.janedeaslart.co.uk/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com