Changed the valid function to use regexes
Removed unneccessary deferred