问题描述:

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>

网友答案:

change you 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 class to you form field , for example :

it is a input text and it is required :

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

or this a 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 you form is valid
    }
}

for more help comment me

网友答案:

Refer this jQuery.validationEngine to know how to use Validation Engine.

For writing Custom rule, refer this existing question jQuery Validate Plugin - How to create a simple custom rule?

网友答案:

all thing go right and you do that correct ,you can just call this method to validate all the field of your form

$('#myForm').validationEngine('validate');

this will return true if all field of your form validate right , else return false

网友答案:

Follow this:

Download jquery validation engine plugin from here. And extract it.

Inside the folder you can find these two files.

jquery.validationEngine-en.js 
jquery.validationEngine.js

Copy & Paste in assets->scripts-> of your working project.

Then change the src path like below.

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

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

In Your Coding do the following:

<script>
    $(document).ready(function(){
        $("#id of ur form").validationEngine();
    });
</script>
相关阅读:
Top