Custom validator that takes a function