unless($username =~ m!^[a-zA-Z0..9-_]+$!) { # throw error ... }