javascript - 使用 jquery 表单验证进行密码验证 jquery.form-validator.js

标签 javascript jquery validation

我正在使用以下代码,我需要匹配表单内的密码。它不适用于此处和其他网站上提供的大多数帮助。我可能错过了一些我无法追踪的东西。请帮我解决这个问题。

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

最佳答案

请引用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

关于javascript - 使用 jquery 表单验证进行密码验证 jquery.form-validator.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37380697/

相关文章:

javascript - 如何从javascript获取Bootstrap 3动态下拉模式对话框中的选定项目

javascript - 如果在某个网页上并离开另一个特定网页则运行脚本

php - Laravel 验证规则的自定义错误消息 : Dimensions

javascript - 使用 Backbone 验证表单

javascript - 如何使用javascript获取表中所有复选框的值?

javascript - jQuery。如何将 JS 变量与标签文字结合起来?

javascript - 如何在弹出窗口中添加链接

validation - Ember-Validations - 不要自动验证

javascript - 谷歌浏览器扩展,将选项卡添加到上下文菜单

javascript - 获取一组单选按钮值