← All demos

Custom Rules with addMethod()

Extend the validator with your own logic using jsValidation.addMethod(name, fn, message).

Example 1 – noSpaces rule

jsValidation.addMethod('noSpaces', function (value) {
  return !/\\s/.test(value);
}, 'Spaces are not allowed.');

Example 2 – strongPassword rule

jsValidation.addMethod('strongPassword', function (value) {
  return /[A-Z]/.test(value) && /[0-9]/.test(value) && /[^A-Za-z0-9]/.test(value);
}, 'Must contain an uppercase letter, a digit, and a special character.');