Pergunta

My problem is i want to validate my form inputs trough jquery.validate. this is my script

$(document).ready(function () {

$('#formreg').validate({ 
    rules: {
        Username: {
            required: true,
            email: true
        },
        Password: {
            required: true,
            minlength: 8
        },
        Password2:{
            required:true,
            minlength:8
        },
        Name:{
            required:true   
        },
        Lastname:{
            required:true
        },
        Address:{
            required:true
        },
        Telephone:{
            required:true
        }
    }
});
return false;
});

with the above code the only validation errors that i get back are only for the email,password2 and address, I want to get the validation errors for all the form inputs. Thank you

This is my html form

<form action="#" method="post" accept-charset="utf-8" id="formreg">    
<input type="text" name="Username" value="" id="Username">
<input type="password" name="Password" value="" id="Password" />
<input type="password" name="Password2" value="" id="Password2"/>  
<input type="text" name="Name" value="" id="Name"/>
<input type="text" name="Lastname" value="" id="Lastname" />
<input type="text" name="Address" value="" id="Address"  />
<input type="text" name="Telephone" value="" id="Telephone"  />    
<button name="Login" type="button"  onclick="submitform();">Register</button>

Foi útil?

Solução

Your button...

<button name="Login" type="button"  onclick="submitform();">Register</button>

You do not need any inline JavaScript with jQuery. And you certainly don't need an onclick handler for the jQuery Validate plugin.

Change your type into submit and remove the inline click handler...

<button name="Login" type="submit">Register</button>

You also cannot put a return false into your DOM ready handler...

$(document).ready(function () {

    $('#formreg').validate({
        // your rules
    });

    // return false;  // <- REMOVE THIS LINE

});

Working DEMO: http://jsfiddle.net/M9Y6L/1/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top