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