different validator

Check if the input value is different with given value

Options

Using with form field
The HTML attributes are used to set the validator options via the Declarative plugin
(* denotes a required option)
NameHTML attributeTypeDescription
compare *data-fv-different___compareString or a function returns a stringThe value that the field has to be different with
messagedata-fv-different___messageStringThe error message
Using with ES6 module
// You might need to change the importing path
import different from 'formvalidation/dist/es6/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:
Take a look at the Asking fields to be unique example if you want to compare more than two fields at the same time
different validator

See also