General validator function.