using jquery validation engine

teddy153 picture teddy153 · Dec 25, 2011 · Viewed 33.1k times · Source

My question i have the above form in my page. i want to validate the form using jquery validation engine.Can you pls tell me how to validate it and what r the files to include. now, i have included the jquery validation engine in my head. i just want to know how to trigger the validation engine and show the error message onblur of the text fields.. many thanks in advance.please find my code below:

<script src="../js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="scripts/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="scripts/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">

    jQuery(document).ready(function(){
        // binds form submission and fields to the validation engine
        $('#myForm').validationEngine('validate');
    });


</script>
<form class="container" id="myForm" method="post" action="">
    <div>
        <span>Field is required : </span>
        <label for="Firstname">Firstname</label>
        <input type="text" class="validate[required] text-input" id="name" name="Firstname"/>
    </div>
    <div>
        <span>Field is required : </span>
        <label for="name">middlename</label>
        <input type="text" id="name" name="middlename" class="validate[required] text-input"/>
    </div>
    <div>
        <span>Field is required : </span>
        <label for="name">lastname</label>
        <input type="text" id="name" name="lastname" class="validate[required] text-input"/>
    </div>
</form>

Answer

Ali Foroughi picture Ali Foroughi · Dec 25, 2011

Change your jquery code to this :

<script type="text/javascript">

   jQuery(document).ready(function(){
       // binds form submission and fields to the validation engine
       $('#myForm').validationEngine();
   });

</script>

Then add some classes to your form field , for example :

it is an input text and it is required :

<input type='text' class="validate[required] text-input">

or this one is an input text for just emails :

<input type='text' class="validate[required,custom[email]] text-input">

put a button and on its Click event call a javascript function like this :

function myValidation()
{

    if ($('#myForm').validationEngine('validate'))   
    { 
        //do somthing here beacause your form is valid
    }
}

For more help comment me