当存在默认值时,如何在Jquery中显示验证错误

当存在默认值时,如何在Jquery中显示验证错误,jquery,validation,input,Jquery,Validation,Input,我是Jquery新手,尝试搜索google everywhere时运气不佳,我正在寻找一个验证规则/或函数来验证表单,并在defautl值在表单中时请求required,因此不将默认值计算为有效值。我尝试了几个代码,但没有成功,我的URL是 Jquery代码是 <script type="text/javascript"> $(document).ready(function() { $("#myform").validate({ valid: functio

我是Jquery新手,尝试搜索google everywhere时运气不佳,我正在寻找一个验证规则/或函数来验证表单,并在defautl值在表单中时请求required,因此不将默认值计算为有效值。我尝试了几个代码,但没有成功,我的URL是

Jquery代码是

<script type="text/javascript">
$(document).ready(function()
{
    $("#myform").validate({
        valid: function(input){
                    var value = $("input").val();
                    if(value == "test"){ return false;}
                       // check input value against your default values
                       // - If match, return false (is NOT valid)
                       // - If no match, return true (is valid)
                     },  

        debug: false,
        rules: {
          name: "required",
          email: {
            required: true,
            email: true
          }
        },

        messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",
        },
        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('proc.php', $("#myform").serialize(), 
                            function(data) {
                $('#light').html(data);
                $('#light').show();
                $('#fade').show();
            });
        }
    });
});
</script>

$(文档).ready(函数()
{
$(“#myform”)。验证({
有效:函数(输入){
var值=$(“输入”).val();
if(value==“test”){return false;}
//对照默认值检查输入值
//-如果匹配,则返回false(无效)
//-如果不匹配,则返回true(有效)
},  
调试:错误,
规则:{
名称:“必需”,
电邮:{
要求:正确,
电子邮件:真的
}
},
信息:{
姓名:“请让我们知道你是谁。”,
电子邮件:“有效的电子邮件将帮助我们与您取得联系。”,
},
submitHandler:函数(表单){
//为有效的表单做其他事情
$.post('proc.php',$(“#myform”).serialize(),
功能(数据){
$('#light').html(数据);
$('#light').show();
$('#淡入').show();
});
}
});
});
其中valid:函数输入是我尝试过的一个,我认为它是最有用的,但是,我不知道在函数中放入什么来验证。感谢您的帮助。
提前谢谢

你是说:

$.validator.addMethod("defaultInvalid", function(value, element) {
    //check if its default value, if yes then invalidate  
    return !(element.value == element.defaultValue); 
});

你是说:

$.validator.addMethod("defaultInvalid", function(value, element) {
    //check if its default value, if yes then invalidate  
    return !(element.value == element.defaultValue); 
});
您的
$(输入)
需要是类或id,不是吗
#

您的
$(输入)
需要是类或id,不是吗<代码>或
#

这是使用默认值进行验证的插件

<form id="formID" class="formular" method="post">
     <input value="This is a placeholder" data-validation-placeholder="This is a placeholder" class="validate[required] text-input" type="text" name="reqplaceholder" id="reqplaceholder" />
</form>



<script>

    jQuery(document).ready(function(){

        // binds form submission and fields to the validation engine

        jQuery("#formID").validationEngine();

    });
</script>

jQuery(文档).ready(函数(){
//将表单提交和字段绑定到验证引擎
jQuery(“#formID”).validationEngine();
});

这是使用默认值进行验证的插件

<form id="formID" class="formular" method="post">
     <input value="This is a placeholder" data-validation-placeholder="This is a placeholder" class="validate[required] text-input" type="text" name="reqplaceholder" id="reqplaceholder" />
</form>



<script>

    jQuery(document).ready(function(){

        // binds form submission and fields to the validation engine

        jQuery("#formID").validationEngine();

    });
</script>

jQuery(文档).ready(函数(){
//将表单提交和字段绑定到验证引擎
jQuery(“#formID”).validationEngine();
});

可能重复可能重复我尝试过,但运气不佳,如果值为“是”,检查代码是什么?在jquery中if条件是如何表述的?我尝试了一下,但没有运气,但是,检查值是否为yes的代码是什么?jquery中的if条件如何表述?谢谢,我有一个问题输入的名称必须是reqplaceholder还是可以是任何内容?谢谢,我有一个问题输入的名称必须是reqplaceholder还是可以是任何内容??