Fixed bug in text validation function