Improvements to input validation

Moved validation to library. Fixes #4
Improved validation regex and added test to qunit. Fixes #2