使用 jquery 验证引擎
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8628955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
using jquery validation engine
提问by teddy153
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:
我的问题我的页面中有上述表格。我想使用 jquery 验证引擎验证表单。你能告诉我如何验证它以及要包含哪些文件。现在,我已经将 jquery 验证引擎包含在我的脑海中。我只想知道如何触发验证引擎并显示文本字段的错误消息 onblur .. 提前非常感谢。请在下面找到我的代码:
<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>
回答by Ali Foroughi
change you jquery code to this :
将您的 jquery 代码更改为:
<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 :
放置一个按钮并在其 Click 事件上调用一个 javascript 函数,如下所示:
function myValidation()
{
if ($('#myForm').validationEngine('validate'))
{
//do somthing here beacause you form is valid
}
}
for more help comment me
如需更多帮助,请评论我
回答by Siva Charan
Refer this jQuery.validationEngineto know how to use Validation Engine.
请参阅此jQuery.validationEngine以了解如何使用验证引擎。
For writing Custom rule, refer this existing question jQuery Validate Plugin - How to create a simple custom rule?
要编写自定义规则,请参阅此现有问题jQuery Validate Plugin - How to create a simple custom rule?
回答by Ali Foroughi
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
如果表单的所有字段都验证正确,这将返回 true ,否则返回 false
回答by Hulk1991
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.
然后更改如下src
路径。
<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>