v0.5.3 is released on 2014.11.05!

different validator

Return true if the input value is different with given field's value

Validators

Improve it on Github

Options

Option HTML attribute Type Description
field* data-bv-different-field String The name of field that will be used to compare with current one.
You also can indicate many fields which names are separated by a comma.
message data-bv-different-message String The error message
When setting options via HTML attributes, remember to enable the validator by setting data-bv-different="true".
When using the different validator, you have to use it for all fields. The plugin will update the message, icon, status of fields properly when you change value of one of any field.

Example

The registration form below doesn't allow the username and password to be the same:

<form id="differentForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-sm-3 control-label">Username</label>
        <div class="col-sm-5">
            <input type="text" class="form-control" name="username" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label">Password</label>
        <div class="col-sm-5">
            <input type="password" class="form-control" name="password" />
        </div>
    </div>
</form>
$(document).ready(function() {
    $('#differentForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                validators: {
                    different: {
                        field: 'password',
                        message: 'The username and password cannot be the same as each other'
                    }
                }
            },
            password: {
                validators: {
                    different: {
                        field: 'username',
                        message: 'The password cannot be the same as username'
                    }
                }
            }
        }
    });
});
<form id="differentForm" class="form-horizontal"
    data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
    data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
    data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">

    <div class="form-group">
        <label class="col-sm-3 control-label">Username</label>
        <div class="col-sm-5">
            <input type="text" class="form-control" name="username"
                data-bv-different="true"
                data-bv-different-field="password"
                data-bv-different-message="The username and password cannot be the same as each other" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label">Password</label>
        <div class="col-sm-5">
            <input type="password" class="form-control" name="password"
                data-bv-different="true"
                data-bv-different-field="username"
                data-bv-different-message="The password cannot be the same as username" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#differentForm').bootstrapValidator();
});
</script>

Related validators

The following validators might be useful to you: