This could work better.
Instead of an alert with a message when you click the button, you could have an a-synchronous call which then displays the message beneath. Perhaps a green tick icon or red cross icon etc.? Also, the textbox shouldn't allow the characters deemed as invalid _before_ the button press.