Fix #1: Add check for valid characters