Use more accurate pattern matching for character validation

#375 didn't really do the trick, but this works more accurately.