PHP validator common method