generic code validity check