Use more accurate pattern matching for character validation