metadata: function (value) { if (validate.isEmpty(value)) { return { presence: { message: 'is required' } }; } return null; },
amount: function (value) { if (validate.isEmpty(value)) { return { presence: { message: 'is required' } }; } if (!validate.isNumber(value)) { return { format: 'must not contain invalid amount. Must be a number.' }; } return null; }
productName: function (value) { if (validate.isEmpty(value)) { return { presence: { message: 'is required' } }; } if (!(/\S/).test(value)) { return { format: 'must not contain invalid productName - eg. Space' }; } return null; },
phoneNumber: function (value) { if (validate.isEmpty(value)) { return { presence: { message: 'is required' } }; } if (!(/^\+?\d+$/).test(value)) { return { format: 'must not contain invalid phone number' }; } return null; },
to: function (value, attributes, attributeName, options, constraints) { if (validate.isEmpty(value)) { return { presence: {message: "is required"} }; } if (!validate.isArray(value) && !validate.isString(value)) { return { format: "must be a string or an array strings (phone numbers)" }; } if (validate.isString(value)) { // TODO: Validate number format let isInvalid = false; if (isInvalid) { return { format: "must be a valid phone number" }; } } if (validate.isArray(value)) { let foundInvalid = false; value.forEach(function (phone) { // TODO: Validate number format }); if (foundInvalid) { return { format: "must NOT contain invalid phone number" } } } return null; },