| Name | HTML attribute | Type | Description |
|---|---|---|---|
callback* | data-fv-callback___callback | Function | The callback method |
message | data-fv-callback___message | String | The error message |
function(input) {// input is an object of// {// value: The field value,// options: The callback validator options// }// Check the field validityreturn true; // or false}
valid and message members:function(input) {// input is an object of// {// value: The field value,// options: The callback validator options// }// ... Do your logic checkingif (...) {return {valid: true, // or falsemessage: 'The error message'};}return {valid: false, // or truemessage: 'Other error message'};}
// You might need to change the importing pathimport callback from 'formvalidation/dist/es6/validators/callback';const result = callback().validate({value: ...,options: {callback: ...,},},});/*result is an object of{valid: true or false,message: The error message}*/
// You might need to change the importing pathimport callback from 'formvalidation/dist/es6/validators/callback';// A very simple method to check the strength of a passwordconst validatePassword = function (input) {const value = input.value;if (value === '') {return { valid: true };}if (value.length < 8) {return {valid: false,message: 'Password must have at least 8 characters',};}if (value === value.toLowerCase()) {return {valid: false,message: 'Password must have at least one uppercase character',};}if (value === value.toUpperCase()) {return {valid: false,message: 'Password must have at least one lowercase character',};}if (value.search(/[0-9]/) < 0) {return {valid: false,message: 'Password must have at least one digit',};}return { valid: true };};const res1 = callback().validate({value: '123456',options: {callback: validatePassword,},});// res1.valid === falseconst res2 = callback().validate({value: 'not.contains.upper',options: {callback: validatePassword,},});// res2.valid === falseconst res3 = callback().validate({value: 'not@CONTAIN@digit',options: {callback: validatePassword,},});// res3.valid === falseconst res4 = callback().validate({value: 'v@l1dP@@',options: {callback: validatePassword,},});// res4.valid === true