Reputation: 77
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>
Upvotes: 2
Views: 36435
Reputation: 4619
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
Upvotes: 10
Reputation: 3163
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>
Upvotes: 1
Reputation: 18064
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?
Upvotes: 7
Reputation: 4619
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
Upvotes: 3