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