2016-05-22 106 views
0

我正在使用以下代碼,我需要匹配表單內的密碼。它不適用於此處和其他網站提供的大部分幫助。我可能錯過了一些我無法追查的東西。請幫我解決一下這個。使用jquery表單驗證的密碼驗證jquery.form-validator.js

HTML

<form id="user_form" class='has-validation-callback'> 
<input type="password" name="pass_confirmation" class="form-control" data-validation="length" data-validation-length="min6"> 
<input type="password" name="pass" id="pass" class="form-control" data-validation-confirm="confirmation" data-validation-help="Please give us some more information"> 
</form> 

的JavaScript

$.validate({ 
    modules : 'security', 
    form : '#user_form', 
    onError : function() { 
     alert('Sorry! Please complete the form fields.'); 
    } 
}); 

鏈接到庫

http://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.19/jquery.form-validator.js 
+1

什麼不工作? – Paul

+0

如果密碼不同,它不會顯示錯誤。 – Indication

回答

0

請參閱password confirmation

This validator can be used to validate that the values of two inputs are the same. The first input should have a name suffixed with _confirmation and the second should have the same name but without the suffix.

<input type="password" name="pass_confirmation" class="form-control" data-validation="length" data-validation-length="min6"> 
<input type="password" name="pass" id="pass" class="form-control" data-validation="confirmation" data-validation-help="Please give us some more information"> 

第二輸入變化屬性data-validation-confirm="confirmation"data-validation="confirmation"它會工作。

工作fiddle

+0

不!不起作用。錯誤:使用未定義的驗證程序「validate_confirmation」。也許你忘記了加載「validate_confirmation」所屬的模塊?你使用的是最新版本的 – Indication

+0

? '' – murli2308

+0

是的,這就是我在題。此外,我試圖解決使用2.2.43版本。 – Indication