2

I'm trying to use ValidationEngine (https://github.com/posabsolute/jQuery-Validation-Engine) I need to validate one field (for email) before the whole form will be validated:

$(document).on("click", "#EmailButton", function(){
    var valid=$("#Email").validationEngine('validate');
    alert(valid);
})
$("#<?=$formName?>").validationEngine({
   promptPosition:'topLeft', 
   scroll: false,
   binded: false,
   onValidationComplete: function(form, status){
if(status==true){                    
           $.ajax({
                type: "POST", ... ... ... }
}

So, when I click on #EmailButton the #Email field should be validated, not whole form.

But when the #EmailButton is clicked, the ajax script from $("#<?=$formName?>").validationEngine({ is run!

I need this feature because I want to make some changes in the form after the #Email field is filled (if email is in Database or not).

How can I validate the #Email field before to run the $("#<?=$formName?>").validationEngine({}) script ?

Thanks.

4

3 回答 3

1

早先的答案是不正确的,如果仅仅是因为 jQuery 验证引擎的代码也不正确的话。由于当前版本中的错误,此代码片段的布尔值实际上是向后的。尝试将“true”更改为“false”,您应该会得到一个有效的结果。这是更正后的示例(假设相关字段的 ID 为“电子邮件”):

function validateEmail() {
    var isValid = !$("#email").validationEngine('validate');

    // You may delete the following two lines after confirming that things are working:
    if (isValid) alert('valid');
    else alert('not valid');

    return isValid; // leave this line in -- it will return the result of validation
}
于 2015-01-20T17:20:15.903 回答
1

尝试这个:

在 HTML 中:

<form id="emailForm">
      Email:<input type="email" id="txtEmail" class="validate[required,custom[email],maxSize[30]]"/>
            <input type="button" value="Email Verify" onclick="emailCheck()"/>  
</form>

在jQuery中:

function emailCheck()
{
    if($("#emailForm").validationEngine('validate') == true)
    {
       alert('valid');
    }
    else
    {
       alert('not valid');
    }
}
于 2013-07-06T10:40:41.320 回答
0
$("#Email").validationEngine('validateField',$("#Email"))
于 2013-05-24T07:41:36.100 回答