fixed js race condition; added regexes to condition user input