regex with space code example Example: space allow in regex Just add a space in your character class. ^[a-zA-Z0-9_ ]*$