different validator

Check if the input value is different with given value

Options

Using with form field

* presents a required option. The HTML attributes are used to set the validator options via the Declarative plugin

Name HTML attribute Type Description
compare* data-fv-different___compare String or a function returns a string The value that the field has to be different with
message data-fv-different___message String The error message

Using with JavaScript module


// You might need to change the importing path
import different from 'formvalidation/validators/different';

const result = different().validate({
    value: ...,
    options: {
        compare: ...,
        message: ...,
    },
});
/*
result is an object of
{
    valid: true or false,
    message: The error message     
}
*/

Basic Example

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

Tip

Take a look at the Asking fields to be unique example if you want to compare more than two fields at the same time

Related validators

The following validators are similar to this one and might be useful to you.

Name Description
identical Check if the value is the same as one of given value