Refactor validation function

Take out the validation logic out of the keyup
event. The idea is to make it possible to run it
in other events, such as pasting, using a suggestion,
etc.

Change-Id: I4c80734c96765000fe57e4400abae58becfba6f6
Merge "Refactor validation function"