removes invalid chars before validation