validate input before save